Skip to content

Commit

Permalink
Ensure sub-bitmaps have a non-zero width and height
Browse files Browse the repository at this point in the history
When images have a width or height greater than zero but less than the sample size, then the sub-bitmap can have a zero width or height, which causes Bitmap.createBitmap() to crash. By ensuring a height of at least 1, we avoid those crashes.

Fatal Exception: java.lang.IllegalArgumentException
height must be > 0
android.graphics.Bitmap.checkWidthHeight (Bitmap.java:413)
android.graphics.Bitmap.createBitmap (Bitmap.java:732)
android.graphics.Bitmap.createBitmap (Bitmap.java:701)
com.google.android.apps.muzei.render.BitmapRegionLoader.decodeRegion (BitmapRegionLoader.kt:177)
com.google.android.apps.muzei.render.GLPicture.<init> (GLPicture.kt:157)
com.google.android.apps.muzei.render.GLPictureKt.toGLPicture (GLPicture.kt:32)
com.google.android.apps.muzei.render.MuzeiBlurRenderer$GLPictureSet.load$muzei_publicBeta (MuzeiBlurRenderer.kt:325)
com.google.android.apps.muzei.render.MuzeiBlurRenderer.setAndConsumeBitmapRegionLoader (MuzeiBlurRenderer.kt:266)
  • Loading branch information
ianhanniballake committed Apr 17, 2018
1 parent efae8dd commit ea19050
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,12 @@ private constructor(private val inputStream: InputStream, private val rotation:
if (options.inBitmap != null &&
(tempRect.width() != unsampledInBitmapWidth || tempRect.height() != unsampledInBitmapHeight)) {
// Need to extract the sub-bitmap
val subBitmapWidth = Math.max(1, tempRect.width() / sampleSize)
val subBitmapHeight = Math.max(1, tempRect.height() / sampleSize)
val subBitmap = Bitmap.createBitmap(
bitmap, 0, 0,
tempRect.width() / sampleSize,
tempRect.height() / sampleSize)
subBitmapWidth,
subBitmapHeight)
if (bitmap != options.inBitmap && bitmap != subBitmap) {
bitmap.recycle()
}
Expand Down

0 comments on commit ea19050

Please sign in to comment.