【问题标题】:Using WCF to send image to Windows Universal App使用 WCF 将图像发送到 Windows 通用应用程序
【发布时间】:2016-10-31 18:56:57
【问题描述】:

我想为我的 UWP 应用提供带有 WCF 的 System.Drawing.Image

问题是客户端需要Windows.UI.Xaml.Media.Imaging.BitmapImage

我尝试了很多解决方案,但都没有奏效。我目前正在将图像作为字节数组传递给客户端,但我找不到将字节数组读入 BitmapImage 的方法。

WCF 客户端使用 .Net 4.6,通用 Windows 应用面向 Windows 10 周年版

【问题讨论】:

    标签: c# wcf uwp win-universal-app


    【解决方案1】:

    这是一个从字节数组创建 BitmapImage 的方法:

    using System;
    using System.IO;
    using System.Threading.Tasks;
    using Windows.UI.Xaml.Media.Imaging;
    ...
    
    private async Task<BitmapImage> CreateBitmapImage(byte[] bytes)
    {
        var bitmapImage = new BitmapImage();
    
        using (var stream = new MemoryStream(bytes))
        {
            await bitmapImage.SetSourceAsync(stream.AsRandomAccessStream());
        }
    
        return bitmapImage;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-20
      • 2021-01-19
      • 2014-06-19
      • 1970-01-01
      • 2014-02-13
      • 2014-07-22
      • 2011-03-18
      • 1970-01-01
      相关资源
      最近更新 更多