avito-tech / krop

Small widget for image cropping in Instagram-like style
MIT License
126 stars 18 forks source link

ZoomableImageView won't show image when bitmap initialize with delay #6

Closed vararg closed 6 years ago

vararg commented 6 years ago

I found this bug when try to set bitmap from image file that was recently shooted via camera. In this case my nexus 5x needs few seconds to render this bitmap to imageview, and looks like ZoomableImageView can't wait this time. Image never showed(except cases when I add breakepoints to it).

So, some details about problem in ZoomableImageView . When inner image render with delay ZoomableImageView can change flag imageRenderedAtLeastOnce to true, but prevMatchViewSize will be with 0 values(because image is physically not rendered yet). And this params will broke method translateMatrixAfterRotate() (yep, divide by zero and Float.NaN as result), and after that our imgMatrix will contain NaN values.

Right now I fix it with changing logic in fitImageToView() if (!isZoomed && !imageRenderedAtLeastOnce) to if ((!isZoomed && !imageRenderedAtLeastOnce) || (prevMatchViewSize.width == 0.0f && prevMatchViewSize.height == 0.0f))

and removing(because in new logic this will never be invoked) if (prevMatchViewSize.width == 0.0f || prevMatchViewSize.height == 0.0f) { savePreviousImageValues() }

solkin commented 6 years ago

Thanks, I'll check this issue and your fix.

vararg commented 6 years ago

Closed with merging https://github.com/avito-tech/krop/pull/7