字节数组到 BitmapImage WP [英] Byte array to BitmapImage WP
本文介绍了字节数组到 BitmapImage WP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 Windows Phone 8 上进行 BitmapImage
序列化,但与桌面 C# 应用程序相比,WP SDK 中似乎缺少很多库...
I'm trying to get BitmapImage
serialization working on Windows Phone 8, but it seems that a lot of libraries are missing from the WP SDK compared to desktop C# apps...
基本上我有一个 Byte
数组,我需要将它解析成一个 BitmapImage
以进行显示,但是我在网上找不到任何东西......任何帮助非常感谢!:)
Basically I've got a Byte
array that I need to parse into a BitmapImage
for displaying, however nothing I could find on the web works... Any help is much appreciated! :)
由于 StackOverflow 的算法认为这个问题太琐碎,我只是将我正在努力将 BitmapImage 转换为 ByteArray 的代码粘贴
public static Byte[] ImageToByteArray(BitmapImage image)
{
using (MemoryStream ms = new MemoryStream())
{
WriteableBitmap btmMap = new WriteableBitmap
(image.PixelWidth, image.PixelHeight);
Extensions.SaveJpeg(btmMap, ms,
image.PixelWidth, image.PixelHeight, 0, 100);
return ms.ToArray();
}
}
推荐答案
public static BitmapImage ByteArraytoBitmap(Byte[] byteArray)
{
MemoryStream stream = new MemoryStream(byteArray);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(stream);
return bitmapImage;
}
这篇关于字节数组到 BitmapImage WP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文