Nathan
Nathan

Reputation: 1520

Change System.Windows.Controls.Image to MemoryStream?

I have a problem in silverlight which I need to convert this image(from database probably will be in bytes) and convert it to MemoryStream. I need to do this so I can use it to export images to PDF files. Any Ideas?

Image myImage = new Image();
myImage.Source = new BitmapImage(new Uri("Resources/cancel.jpg", UriKind.RelativeOrAbsolute));

For starters, I am trying to convert an Image object to a memory stream object in a sample project(that's why UriSource is coded). Because I'm not familiar with creating dummy data in bytes. Any help on this one? Can I convert an Image to MemoryStream? if not, I believe bytes can be converted to stream, how can I do dummy data?

Thanks for all the replies.

Upvotes: 0

Views: 703

Answers (1)

Arsen Mkrtchyan
Arsen Mkrtchyan

Reputation: 50712

You just need to pass byte[] to MemoryStream constructor

byte[] bytes = GetBytes();
MemoryStream ms = new MemoryStream(bytes);

Hope this helps

Upvotes: 1

Related Questions