Windows中的BitmapImage WriteableBitmap - metro

时间:2013-04-23 14:37:35

标签: visual-studio-2012 windows-store-apps

如何在Metro应用程序中将BitmapImage转换为WriteableBitmap对象? 我一直在寻找,但我没有在哪里 任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

据我所知,没有第三方图书馆真的很难。

您仍然可以从 StorageFile 创建 WritableBitmap

public static async Task<WriteableBitmap> writableImageFromFile(StorageFile file)
{
    IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read);

    WriteableBitmap writableBitmap = new WriteableBitmap(1, 1);
    writableBitmap.SetSource(fileStream);

    return writableBitmap;
}

不要忘记这一点:

using System;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Storage.Streams;
using Windows.UI.Xaml.Media.Imaging;