简体   繁体   中英

Using WCF to send image to Windows Universal App

I want serve an System.Drawing.Image with WCF to my UWP App.

The problem is that the client needs a Windows.UI.Xaml.Media.Imaging.BitmapImage

I've tried lot's of solutions but nothing worked. I'm currently passing the image as a byte array to the client, but I can't find a way to read the byte array into an BitmapImage.

The WCF client is using .Net 4.6 and the Universal Windows App is targeting Windows 10 Anniversary Edition

Here is a method that creates a BitmapImage from a byte array:

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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