How to clear a bitmap?

I create a new empty transparent Bitmap and make some changes to it.

Is there a way to clear this (make it transparent and empty again) without creating a new instance of Bitmap ?

UPDATE: Thanks for your help. I have found the answer.

 // Fills the bitmap pixels with the specified Color. bitmap.eraseColor(somecolor); 
+6
source share
2 answers

Try the following:

 myBitmap.eraseColor(android.graphics.Color.TRANSPARENT); 

The constant value of int TRANSPARENT is 0x00000000.

+13
source

Your bitmap should be a modified bitmap.

when your bitmap is like this

Bitmap bitmap = .......

then convert it to a mutable bitmap using below

Bitmap mutableBitmap = bitmap.copy (bitmap .Config.ARGB_8888, true);

then mutableBitmap.eraseColor (somecolor);

0
source

Source: https://habr.com/ru/post/890321/


All Articles