Converting WriteableBitmap to stream on WP8

南楼画角 提交于 2019-12-10 21:05:56

问题


How can I convert a WriteableBitmap to stream on WP8 platform?

Final goal is to dump the image output produced by native code to the CameraRoll library using SavePictureToCameraRoll(filename, stream)


回答1:


You can encode your bitmap to stream with WritableBitmap.SaveJpeg method and use this stream as a parameter to MediaLibrary.SavePictureToCameraRoll.
Note: before calling MediaLibrary.SavePictureToCameraRoll don't forget to set the stream position to 0 if you're using a MemoryStream. Like this:

var wb = new WriteableBitmap(bitmap);
var fileStream = new MemoryStream();
wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 100, 100);
fileStream.Seek(0, SeekOrigin.Begin);

var m = new MediaLibrary();
m.SavePictureToCameraRoll("test", fileStream);


来源:https://stackoverflow.com/questions/16913485/converting-writeablebitmap-to-stream-on-wp8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!