Reputation: 17010
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?
Upvotes: 24
Views: 23356
Reputation: 41
You can do this very easy but it depends on the application. If you have an application that prompts the user for a drawing input, like signature or anything similar, you will usually have an ArrayList of Paths which are drawn to the Canvas of that View. 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.
Upvotes: 0
Reputation: 17010
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
}
Upvotes: 45