码迷,mamicode.com
首页 > Windows程序 > 详细

在UWP 将BitmapImage转换为 WriteableBitmap

时间:2017-10-10 09:54:22      阅读:618      评论:0      收藏:0      [点我收藏+]

标签:lte   dom   wan   window   hub   ica   type   lan   async   

原文: How to convert BitmapImage to WriteableBitmap in Universal application for windows 10?

您可以直接从文件将图像加载到WriteableBitmap对象。

var filePicker = new FileOpenPicker();
filePicker.FileTypeFilter.Add(".jpg");
var result = await filePicker.PickSingleFileAsync();

if (result != null)
{
    using (IRandomAccessStream stream = await result.OpenAsync(FileAccessMode.Read))
    {
        BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);
        WriteableBitmap bmp = new WriteableBitmap((int)decoder.PixelWidth, (int)decoder.PixelHeight);
        bmp.SetSource(stream);

        // show the image in the UI if you want.
        MyImage.Source = bmp;
    }
}
这样你可以使用WriteableBitmap,你可以使用WriteableBitmapEx库。

  

在UWP 将BitmapImage转换为 WriteableBitmap

标签:lte   dom   wan   window   hub   ica   type   lan   async   

原文地址:http://www.cnblogs.com/lonelyxmas/p/7643923.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!