简体   繁体   中英

Convert StorageFile to WriteableBitmap WP8.1 Silverlight

I am developing this application where I am able to get all the pictures from picture library as StorageFile data type. now I want to change it to writeablebitmap, apply a sketch filter and show in image control. can someone please help me in changing the data type from StorageFile to writeablebitmap?

here is my code:

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

}

This code works for me.

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

Try this, it should work:

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

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