How to convert a Memory stream to a Bitmap
-
Thursday, November 10, 2011 3:42 AMI use the code snipet below to create an image with bytes from server, it worked in Silverlight and WP7. But, how to do the same work in Windows 8? Any advice and suggestion will be appreciated. BitmapImage image = new BitmapImage(); var stream = new MemoryStream(response.ByteData); stream.Write(response.ByteData, 0, response.ByteData.Length); image.SetSource(stream);
All Replies
-
Thursday, November 10, 2011 6:35 AM
I think you don't need to read/write the stream, here's a snippet that reads a stream from a file:
also have a look at this interesting post: http://www.charlespetzold.com/blog/2011/11/080203.htmlasync internal void DoOpenFile(IReadOnlyList<Windows.Storage.IStorageItem> files) { StorageFile file = files[0] as StorageFile; IRandomAccessStream readStream = await file.OpenAsync(FileAccessMode.Read); BitmapImage img = new BitmapImage(); img.SetSource(readStream); detailImage.Source = img; }
Corrado Cavalli [Microsoft .NET MVP-MCP]
UGIdotNET - http://www.ugidotnet.org
Weblog: http://blogs.ugidotnet.org/corrado/
Twitter: http://twitter.com/corcav- Proposed As Answer by HeToCMicrosoft Community Contributor Thursday, November 10, 2011 11:58 AM
- Marked As Answer by Bob_BaoMVP, Moderator Tuesday, November 22, 2011 7:37 AM


