Search code examples
androidbitmapimagedecoder

How to get mutable bitmap using ImageDecoder?


I am creating bitmap as follows

       ImageDecoder.Source source = ImageDecoder.createSource(this.getContentResolver(), mSourceUri);
        try {
            bitmap = ImageDecoder.decodeBitmap(source));
        } catch (IOException e) {
            e.printStackTrace();
        }

This returns immutable bitmap. I saw google documentation and there is a method setMutableRequired() but I couldn't find how to use this method. It doesn't work on ImageDecoder as well as source


Solution

  • A bit prettier solution

    imageBitmap = imageBitmap.copy(Bitmap.Config.ARGB_8888, true);
    

    Refer this answer