android / android-ktx

A set of Kotlin extensions for Android app development.
https://android.github.io/android-ktx/core-ktx/
7.48k stars 565 forks source link

Adding extensions to check if the bitmap is empty or not #571

Closed kevalpatel2106 closed 1 year ago

kevalpatel2106 commented 6 years ago

Extension functions to check if the bitmap is empty or not using byte counts. See #568 .

Usage:

if (bitmap.isEmpty()){
   // Did not read bitmap correctly.
}

or

if (bitmap.isNullOrEmpty()){
   // Bitmap is either null or empty
}
romainguy commented 6 years ago

Thanks for the PR. This however only indicates whether the bitmap was allocated, not whether the bitmap is empty. Moreover, we don't give a way to allocate 0x0 bitmaps, so I'm not even sure in which situations you could get a Bitmap with an allocation count of 0.

kevalpatel2106 commented 6 years ago

I had an issue once where the server was sending invalid image bitmap size was zero after bitmap was generated from an input stream. These methods can help to check for the correct bitmap size.