title: BitmapImage OutOfMemoryException only in Windows 8.1
body: <p>I've installed Windows 8.1 recently to try, and my pet project is crashing on it (same binary works fine on one Win7 and two Win8 machines).</p>
  
  <p>OutOfMemoryException is being thrown in BitmapImage.EndInit:</p>
  
  <pre><code>    public static BitmapImage GetResourceImage(string resourcePath, int decodePixelWidth = 0, int decodePixelHeight = 0)
      {
          var image = new BitmapImage();
  
          var moduleName = Assembly.GetExecutingAssembly().GetName().Name;
          var resourceLocation = string.Format("pack://application:,,,/{0};component/Resources/{1}", moduleName, resourcePath);
  
          image.BeginInit();
          image.UriSource = new Uri(resourceLocation);
          image.DecodePixelWidth = decodePixelWidth;
          image.DecodePixelHeight = decodePixelHeight;
          image.EndInit();
          image.Freeze();
  
          return image;
      }
  </code></pre>
  
  <ul>
  <li>Task manager readings for the process on crash: 27MB memory, 302 handles, 12 threads, 36 user objects, 34 GDI objects, 5.3 GB RAM available</li>
  <li>Platform target is x86 (required because of native DLL usage)</li>
  <li>Method is called many times for different (random) images (there are ~250 bmp files in resources)</li>
  <li>decodePixelWidth/Height are random, but within valid range  </li>
  <li>exception happens on different resource paths and sizes</li>
  <li>exception happens only when DecodePixelWidth or DecodePixelHeight is not 0</li>
  <li>exception never happens if I comment out DecodePixelWidth and DecodePixelHeight setters and let it load to original size</li>
  </ul>
  
  <p>As I understand from googling, it has something to do with GDI internals, but I can't find a fix or workaround. Any ideas (besides using some other mechanism to decode and/or resize images - I only need raw pixel data)? </p>
  
  <p>Complete project source code can be found here (link is to the file in question): <a href="https://code.google.com/p/lander-net/source/browse/trunk/csharp/LanderNet/Util/BitmapUtils.cs" rel="nofollow">https://code.google.com/p/lander-net/source/browse/trunk/csharp/LanderNet/Util/BitmapUtils.cs</a></p>
  
  <p><strong>UPDATE:</strong>
  I've tried to use TransformedBitmap for resizing, it fails with the same exception.</p>