【问题标题】:Byte array to BitmapImage WP字节数组到 BitmapImage WP
【发布时间】:2013-07-20 13:27:41
【问题描述】:

我正在尝试让BitmapImage 序列化在 Windows Phone 8 上工作,但与桌面 C# 应用程序相比,WP SDK 似乎缺少很多库...

基本上我有一个Byte 数组,我需要将其解析为BitmapImage 以进行显示,但是我在网络上找不到任何东西...非常感谢任何帮助! :)

由于 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();
        }
    }

【问题讨论】:

    标签: c# serialization windows-phone-8


    【解决方案1】:
    public static BitmapImage ByteArraytoBitmap(Byte[] byteArray)
    {
        MemoryStream stream = new MemoryStream(byteArray);
        BitmapImage bitmapImage = new BitmapImage();
        bitmapImage.SetSource(stream);
        return bitmapImage;
    }
    

    【讨论】:

    • 非常感谢!我之前确实尝试过使用流,但我使用了DataReader 而不是MemoryStream :)
    • 您使用的是哪个版本的框架?我在 BitmapImage 中找不到 SetSource 方法!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-11
    • 2016-06-20
    • 2013-08-15
    • 2016-07-06
    相关资源
    最近更新 更多