WriteableBitmap的转换为Byte数组 - 的Windows phone 8.1 - Silverlight的 [英] Converting WriteableBitmap to Byte array - Windows phone 8.1 - Silverlight

查看:308
本文介绍了WriteableBitmap的转换为Byte数组 - 的Windows phone 8.1 - Silverlight的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现网页下面的代码WriteableBitmap的转换为字节数组,但是这个代码不与Silverlight的工作。有人可以告诉我,使其与Silverlight的工作,需要什么样的变化。

 字节[] ConvertBitmapToByteArray(WriteableBitmap的位图)
{
WriteableBitmap的BMP位图=;

使用(流流= bmp.PixelBuffer.AsStream())
{
的MemoryStream MemoryStream的=新的MemoryStream();
stream.CopyTo(MemoryStream的);
返回memoryStream.ToArray();
}
}



它提供了以下错误信息:




System.Windows.Media.Imaging.WriteableBitmap'不包含'PixelBuffer的定义,并没有扩展方法'PixelBuffer接受的第一个参数类型'System.Windows.Media.Imaging.WriteableBitmap'可以找到(是否缺少using指令或程序集引用?)



解决方案

我在另一个项目中使用此方法。这个片段属于的萨拉·席尔瓦

 公共静态的byte [] ConvertToByteArray(WriteableBitmap的WriteableBitmap的)
{
使用(VAR毫秒=新的MemoryStream())
{
writeableBitmap.SaveJpeg(MS,writeableBitmap.PixelWidth,writeableBitmap.PixelHeight,0,100);
返回ms.ToArray();
}
}

MSDN文档


I found the following code on web to convert WriteableBitmap to byte array but this code does not work with Silverlight. Can someone please tell me what changes are needed to make it work with Silverlight.

byte[] ConvertBitmapToByteArray(WriteableBitmap bitmap)
{
    WriteableBitmap bmp = bitmap;

    using (Stream stream = bmp.PixelBuffer.AsStream())
    {
        MemoryStream memoryStream = new MemoryStream();
        stream.CopyTo(memoryStream);
        return memoryStream.ToArray();
    }
}

It gives the following error message:

'System.Windows.Media.Imaging.WriteableBitmap' does not contain a definition for 'PixelBuffer' and no extension method 'PixelBuffer' accepting a first argument of type 'System.Windows.Media.Imaging.WriteableBitmap' could be found (are you missing a using directive or an assembly reference?)

解决方案

I used this method in another project. This snippet belongs to sara silva.

public static byte[] ConvertToByteArray(WriteableBitmap writeableBitmap)
{
    using (var ms = new MemoryStream())
    {
        writeableBitmap.SaveJpeg(ms, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, 0, 100);
        return ms.ToArray();
    }
}

msdn documentation

这篇关于WriteableBitmap的转换为Byte数组 - 的Windows phone 8.1 - Silverlight的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆