简体   繁体   English

如何在wp7中将位图图像转换为字节数组?

[英]How to convert Bitmap image to byte array in wp7?

using (MemoryStream ms = new MemoryStream())
{
    image.CreateOptions = BitmapCreateOptions.None;
    image.UriSource = new Uri("/Images/chef.png", UriKind.Relative);              

    WriteableBitmap LoadedPhoto = new WriteableBitmap(image);
    LoadedPhoto.SaveJpeg(ms, LoadedPhoto.PixelWidth, LoadedPhoto.PixelHeight,0,95);
    ms.Seek(0, 0);
    byte[] data = new byte[ms.Length];
    ms.Read(data, 0, data.Length);
    ms.Close();
 }

I am getting NullReferenceException at image, but my path is also correct and image also exists. 我在图像处收到NullReferenceException,但我的路径也是正确的,图像也存在。

WriteableBitmap LoadedPhoto = new WriteableBitmap(image);

Is anything goes wrong. 有什么事吗

Please Refer the solution. 请参考解决方案。 which shows the solution to converting the bitmapimages to byte array. 该图显示了将位图图像转换为字节数组的解决方案。

I hope you will understand.. conversion of bitmapimage to byte array 我希望你能理解.. bitmapimage转换为字节数组

Refer this link.. 请参阅此链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM