我可以從Assets中的圖片創建WriteableBitmap。如何從BitmapImage創建WriteableBitmap?
Uri imageUri1 = new Uri("ms-appx:///Assets/sample1.jpg");
WriteableBitmap writeableBmp = await new WriteableBitmap(1, 1).FromContent(imageUri1);
但是,我無法從圖片目錄創建WriteableBitmap的,(我使用WinRT XAML Toolkit)
//open image
StorageFolder picturesFolder = KnownFolders.PicturesLibrary;
StorageFile file = await picturesFolder.GetFileAsync("sample2.jpg");
var stream = await file.OpenReadAsync();
//create bitmap
BitmapImage bitmap2 = new BitmapImage();
bitmap2.SetSource();
bitmap2.SetSource(stream);
//create WriteableBitmap, but cannot
WriteableBitmap writeableBmp3 =
await WriteableBitmapFromBitmapImageExtension.FromBitmapImage(bitmap2);
這是正確的嗎?
謝謝你的回答,但是如何從get go打開圖像作爲writeablebitmap,?我認爲[這](http://stackoverflow.com/questions/4254225/opening-an-image-file-into-writablebitmap)可能會有所幫助,但我不能將位圖直接傳遞到一個可寫位圖。 – a2hiro
沒有該鏈接適用於Silverlight。您需要爲圖像獲取StorageFile,例如使用文件選取器,然後等待OpenReadAsync,然後創建1x1 WriteableBitmap並等待SetSourceAsync。檢查此示例/擴展:http://winrtxamltoolkit.codeplex.com/SourceControl/changeset/view/4d568d4e4c6a#WinRTXamlToolkit/Imaging/WriteableBitmapLoadExtensions.cs –