簡體   English   中英

將StorageFile轉換為WriteableBitmap WP8.1 Silverlight

[英]Convert StorageFile to WriteableBitmap WP8.1 Silverlight

我正在開發此應用程序,在這里我可以從圖片庫中獲取所有圖片作為StorageFile數據類型。 現在,我想將其更改為writeablebitmap,應用草圖濾鏡並在圖像控件中顯示。 有人可以幫我將數據類型從StorageFile更改為writeablebitmap嗎?

這是我的代碼:

StorageFolderpicturesFolder = KnownFolders.PicturesLibrary;

IReadOnlyList<IStorageFile> file = await picturesFolder.GetFilesAsync(CommonFileQuery.OrderByDate);

if(file.Count > 0)

 {

foreach(StorageFile f in file)

 { 

// the code for changing the data type will go here

}

該代碼對我有用。

if (file.Count > 0)
{          
    foreach (StorageFile f in file)
    {
        ImageProperties properties = await f.Properties.GetImagePropertiesAsync();
        WriteableBitmap bmp = new WriteableBitmap((int)properties.Width, (int)properties.Height);
        bmp.SetSource((await f.OpenReadAsync()).AsStream());

        // Ready to go with bmp
    }
}

試試這個,它應該可以工作:

IReadOnlyList<IStorageFile> files = await picturesFolder.GetFilesAsync(CommonFileQuery.OrderByDate);

if(files.Count > 0)
{
    var images = new List<WriteableBitmap>();
    foreach(var f in files)
    { 
         var bitmap = new WriteableBitmap(500, 500);
         using (var stream = await f.OpenAsync(FileAccessMode.ReadWrite))
         {
             bitmap.SetSource(stream);
         }
         images.Add(bitmap);
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM