Loading a resource to a mutable bitmap

后端 未结 5 1967
面向向阳花
面向向阳花 2020-12-05 10:52

I am loading a bitmap from a resource like so:

 Bitmap mBackground = BitmapFactory.decodeResource(res,R.drawable.image);

What I want to do

相关标签:
5条回答
  • 2020-12-05 11:02

    Instad of yours:

    Bitmap mBackground = BitmapFactory.decodeResource(res,R.drawable.image);
    

    Use:

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inMutable = true;
    
    Bitmap mBackground = BitmapFactory.decodeResource(res,R.drawable.image, options);
    
    0 讨论(0)
  • 2020-12-05 11:06

    You'd better use RapidDecoder.

    import rapid.decoder.BitmapDecoder;
    
    Bitmap mBackground = BitmapDecoder.from(res, R.drawable.image)
            .mutable().decode();
    

    Works for API level 8.

    0 讨论(0)
  • 2020-12-05 11:11

    in case you need to handle all API levels, check out this post:

    https://stackoverflow.com/a/16314940/878126

    0 讨论(0)
  • 2020-12-05 11:18

    There are several ways to create a copy of it. This thread might help you: http://www.anddev.org/how_to_modify_the_image_file-t513.html

    0 讨论(0)
  • 2020-12-05 11:21

    Use decodeResource(Resources res, int id, BitmapFactory.Options opts) and specify inMutable in the options.

    http://developer.android.com/reference/android/graphics/BitmapFactory.html

    0 讨论(0)
提交回复
热议问题