Skip to content
This repository has been archived by the owner on Mar 30, 2019. It is now read-only.

TextureLoader.LoadBitmap() does not dispose of resources correctly #45

Open
LordBenjamin opened this issue Sep 19, 2016 · 0 comments
Open

Comments

@LordBenjamin
Copy link

LordBenjamin commented Sep 19, 2016

Calling TextureLoader.LoadBitmap() results in the target file being locked for the lifetime of the process. This is because it does not dispose of the BitmapDecoder or BitmapDecodeFrame objects that it creates.

The code below fixed for me:

    public static BitmapSource LoadBitmap(ImagingFactory factory, string filename) {
        using (var bitmapDecoder = CreateBitmapDecoder(factory, filename)) {
            using (var frame = bitmapDecoder.GetFrame(0)) {
                var formatConverter = new FormatConverter(factory);

                formatConverter.Initialize(
                    frame,
                    PixelFormat.Format32bppPRGBA,
                    BitmapDitherType.None,
                    null,
                    0.0,
                    BitmapPaletteType.Custom);

                return formatConverter;
            }
        }
    }

    private static BitmapDecoder CreateBitmapDecoder(ImagingFactory factory, string filename) {
        return new BitmapDecoder(
            factory,
            filename,
            DecodeOptions.CacheOnDemand);
    }
@xoofx xoofx added bug and removed bug labels Sep 19, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants