Description
When using AsBitmap() it leaks memory and causes application failures that depend on the Bitmap object. This is due to the custom pointer we create and manually setting the stride.
Reproduction Steps
Load a large raw image using the following algorithm
Bitmap GetMyImage()
{
using (var image = new RawImage("/path/to/raw/file"))
using (var raw = image.UnpackRaw())
{
raw.Process(new DcrawProcessor());
using (var processed = raw.AsProcessedImage())
return processed.AsBitmap();
}
}
The above code will still leak even if you manually managed the IDisposable and implement this inside of a wrapper. Once you start zooming in on the bitmap in the UI application it will quickly run out of memory
Workaround
The best workaround I could find was converting the image to a Bitmap saving it to disk and then loading the .bmp file into memory and returning it.
Bitmap GetMyImage()
{
using (var image = new RawImage("/path/to/raw/file"))
using (var raw = image.UnpackRaw())
{
raw.Process(new DcrawProcessor());
using (var processed = raw.AsProcessedImage())
using (var bitmap = processed.AsBitmap())
bitmap.Save("temp.bmp", ImageFormat.Bmp);
return new Bitmap("temp.bmp");
}
}
Description
When using
AsBitmap()it leaks memory and causes application failures that depend on theBitmapobject. This is due to the custom pointer we create and manually setting the stride.Reproduction Steps
Load a large raw image using the following algorithm
The above code will still leak even if you manually managed the
IDisposableand implement this inside of a wrapper. Once you start zooming in on the bitmap in the UI application it will quickly run out of memoryWorkaround
The best workaround I could find was converting the image to a
Bitmapsaving it to disk and then loading the.bmpfile into memory and returning it.