Home > Windows 8, WPF > Windows 8.1 OutOfMemoryException when rendering Bitmaps

Windows 8.1 OutOfMemoryException when rendering Bitmaps

Recently, I have been faced to a strange issue in one of our application.
That application has been validated to work on bigger screen size, and we notice at that time that bitmaps graphics was badly render on such big screen mainly due to different pixel size.

To solve that bad rendering of such bitmap on such screen size, we had to use the BitmapScalingMode property of an Image control.

<StackPanel>
<Image RenderOptions.BitmapScalingMode=”HighQuality” Source=”/Resources/key.png” Width=”40″ Height=”40″ Stretch=”Fill” VerticalAlignment=”Center”/>
</StackPanel>

Has shown is sample code above, setting the property to HighQuality value was rendering the image nicely on bigger screen. So far so good then.

Next steps was to test the application on this same type of screen but under Windows 8, working perfectly well as well until the time it has been updated to Windows 8.1 and get our application crash with an OutOfMemoryException.

After days of testing we have identify that it was occurring when used image was about 8 bits and 256 colors. This has been reported as a bug by Microsoft on Windows 8.1 update.

Different possible Work around:

  1. With your prefer      graphic tool generate a files from your image with more depth
  2. If you have no      control of the image you have and want to still use it you card converted      from code by the following code snippets

    BitmapSource ResizeImage(BitmapSource image, int width, int height)
    {
    var      bmp = new FormatConvertedBitmap(image, PixelFormats.Bgr24, null, 0);
    return      new TransformedBitmap(bmp, new      ScaleTransform((double)width/bmp.PixelWidth,      (double)height/bmp.PixelHeight));
    }

Hope this will save you some times 🙂

Advertisements
Categories: Windows 8, WPF Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: