问题
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?
回答1:
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
}
回答2:
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 :)
来源:https://stackoverflow.com/questions/28767466/how-to-check-if-a-bitmap-is-empty-blank-on-android