How can I check if a Bitmap
object is completely blank, i.e. all its pixels are transparent, without a x-y loop on every pixel?
You can do a check when you want to return the BitMap look to see if the ArrayList of Paths is bigger than 0 and return the BitMap if so, or else return null.
asShared. Return an immutable bitmap backed by shared memory which can be efficiently passed between processes via Parcelable. If this bitmap already meets these criteria it will return itself. This value cannot be null .
You can check your Bitmap instance (in the example myBitmap
) against an empty one with:
Bitmap emptyBitmap = Bitmap.createBitmap(myBitmap.getWidth(), myBitmap.getHeight(), myBitmap.getConfig()); if (myBitmap.sameAs(emptyBitmap)) { // myBitmap is empty/blank }
This is not an efficient way to solve the problem but it does its purpose cause I didn't find a solution even in docs
see while the Bitmap is null it's width or height can't be fetched and it raises a crash so here is may solve your problem
try{ int check=bitmap.getWidth(); // the bitmap is valid & not null or empty }catch (Exception w){ // the bitmap, not valid eighter null or empty }
hope this helps :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With