I am using the WebClient to download a picture based on a Uri that was fished out from a database by a service. The returned stream from the WebClient is then used to create a BitmapImage which is then set as the source for an Image control. This all works
fine.
The problem pops up when I do a MouseEnter event for the Image control. On the event I would like to pass the Image.Source to a new ImageBrush to use it as a fill for a Rectangle control. The problem is that since the source wasn't a path of a picture in
the application but a stream i get an error.
Is there a way to pass the underlying image data/stream from the image control (knowing that it's source was a stream) to the image.brush or am I left with having to keep the Stream somewhere and use it everytime i want to reproduce the picture in a different
Image or any other control that might use it.
Cooxter
Member
8 Points
6 Posts
Passing Image.Source that was created from a Stream.
Mar 14, 2008 11:05 AM | LINK
My problem is as follows:
I am using the WebClient to download a picture based on a Uri that was fished out from a database by a service. The returned stream from the WebClient is then used to create a BitmapImage which is then set as the source for an Image control. This all works fine.
The problem pops up when I do a MouseEnter event for the Image control. On the event I would like to pass the Image.Source to a new ImageBrush to use it as a fill for a Rectangle control. The problem is that since the source wasn't a path of a picture in the application but a stream i get an error.
Is there a way to pass the underlying image data/stream from the image control (knowing that it's source was a stream) to the image.brush or am I left with having to keep the Stream somewhere and use it everytime i want to reproduce the picture in a different Image or any other control that might use it.
jjy2
Member
354 Points
155 Posts
Re: Passing Image.Source that was created from a Stream.
Mar 14, 2008 11:20 AM | LINK
I am not sure if it is good practice but I just keep StreamResourceInfo object in a Dictionary.
Unlike Downloader class in SL1.1, I don't see documentation saying that you shouldn't cache it.
So I figured I can just cache it.
jjy2
Member
354 Points
155 Posts
Re: Passing Image.Source that was created from a Stream.
Mar 14, 2008 11:56 AM | LINK
Also unlike SL1.1, It seem now we can share brush object between frameworkelements so you might as well just keep the brush.
Cooxter
Member
8 Points
6 Posts
Re: Passing Image.Source that was created from a Stream.
Mar 14, 2008 03:05 PM | LINK
Thanks for the reply. Yeah i guess i'll keep the stream in a Dictionary then.