@@ -1249,10 +1249,10 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
12491249 setLayoutParams (origParams );
12501250
12511251 if (mBitmap != null ) {
1252- applyImageMatrix (r - l , b - t , false , false );
1252+ applyImageMatrix (r - l , b - t , true , false );
12531253
12541254 // after state restore we want to restore the window crop, possible only after widget size is known
1255- if (mBitmap != null && mRestoreCropWindowRect != null ) {
1255+ if (mRestoreCropWindowRect != null ) {
12561256 mImageMatrix .mapRect (mRestoreCropWindowRect );
12571257 mCropOverlayView .setCropWindowRect (mRestoreCropWindowRect );
12581258 handleCropWindowChanged (false , false );
@@ -1309,7 +1309,6 @@ private void handleCropWindowChanged(boolean inProgress, boolean animate) {
13091309 mAnimation .setStartState (mImagePoints , mImageMatrix );
13101310 }
13111311
1312- updateCropRectByZoomChange (newZoom / mZoom );
13131312 mZoom = newZoom ;
13141313
13151314 applyImageMatrix (width , height , true , animate );
@@ -1318,19 +1317,6 @@ private void handleCropWindowChanged(boolean inProgress, boolean animate) {
13181317 }
13191318 }
13201319
1321- /**
1322- * Adjust the given crop window rectangle by the change in zoom, need to update the location and size
1323- * of the crop rectangle to cover the same area in new zoom level.
1324- */
1325- private void updateCropRectByZoomChange (float zoomChange ) {
1326- RectF cropRect = mCropOverlayView .getCropWindowRect ();
1327- float xCenterOffset = getWidth () / 2 - cropRect .centerX ();
1328- float yCenterOffset = getHeight () / 2 - cropRect .centerY ();
1329- cropRect .offset (xCenterOffset - xCenterOffset * zoomChange , yCenterOffset - yCenterOffset * zoomChange );
1330- cropRect .inset ((cropRect .width () - cropRect .width () * zoomChange ) / 2f , (cropRect .height () - cropRect .height () * zoomChange ) / 2f );
1331- mCropOverlayView .setCropWindowRect (cropRect );
1332- }
1333-
13341320 /**
13351321 * Apply matrix to handle the image inside the image view.
13361322 *
@@ -1340,6 +1326,10 @@ private void updateCropRectByZoomChange(float zoomChange) {
13401326 private void applyImageMatrix (float width , float height , boolean center , boolean animate ) {
13411327 if (mBitmap != null && width > 0 && height > 0 ) {
13421328
1329+ mImageMatrix .invert (mImageInverseMatrix );
1330+ RectF cropRect = mCropOverlayView .getCropWindowRect ();
1331+ mImageInverseMatrix .mapRect (cropRect );
1332+
13431333 mImageMatrix .reset ();
13441334
13451335 // move the image to the center of the image view first so we can manipulate it from there
@@ -1363,10 +1353,7 @@ private void applyImageMatrix(float width, float height, boolean center, boolean
13631353 mImageMatrix .postScale (mZoom , mZoom , BitmapUtils .getRectCenterX (mImagePoints ), BitmapUtils .getRectCenterY (mImagePoints ));
13641354 mapImagePointsByImageMatrix ();
13651355
1366- RectF cropRect = mCropOverlayView .getCropWindowRect ();
1367-
1368- // reset the crop window offset so we can update it to required value
1369- cropRect .offset (-mZoomOffsetX * mZoom , -mZoomOffsetY * mZoom );
1356+ mImageMatrix .mapRect (cropRect );
13701357
13711358 if (center ) {
13721359 // set the zoomed area to be as to the center of cropping window as possible
0 commit comments