locked
Error when using Bitmap.SetSource

    Question

  • hi,

    I'm working on an app which loads images from a chosen folder to a gridView.

    when I use SetSource to set the BitmapImage source I receive an error "insufficient memory" after loading some of the images.

    when I use the constructor with a Uri path it works fine. but it will only display images from the projects directory.

    StorageFolder folder = await StorageApplicationPermissions.FutureAccessList.GetFolderAsync(RecentToken);
    StorageFile file = await folder.GetFileAsync(path);
    IRandomAccessStream stream = await file.OpenReadAsync();
    image = new BitmapImage(new Uri(file.Path));//loads only within project directory
    image.SetSource(stream);//causes insufficient memory
    stream.Dispose();
    
    

     


    Spaarvap

    Monday, July 14, 2014 2:32 PM

Answers

  • How big are the images? Have you tried loading them at a smaller size by setting the BitmapImage's  DecodePixelHeight and DecodePixelWidth properties?
    • Marked as answer by spaarvap Monday, July 14, 2014 2:45 PM
    Monday, July 14, 2014 2:40 PM
    Owner

All replies

  • How big are the images? Have you tried loading them at a smaller size by setting the BitmapImage's  DecodePixelHeight and DecodePixelWidth properties?
    • Marked as answer by spaarvap Monday, July 14, 2014 2:45 PM
    Monday, July 14, 2014 2:40 PM
    Owner
  • Thanks!

    I set DecodePixelHeight to the size of the Displayed image and it works fine now!


    Spaarvap

    Monday, July 14, 2014 2:45 PM