How to check if a Bitmap is empty (blank) on Android

lorenzo-s picture lorenzo-s · Feb 27, 2015 · Viewed 16.6k times · Source

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?

Answer

lorenzo-s picture lorenzo-s · Feb 27, 2015

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
}