Skip to content

Commit 0e923fc

Browse files
committed
fix image rotation breaking min/max crop result restrictions #401
1 parent 2726e5e commit 0e923fc

4 files changed

Lines changed: 23 additions & 10 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ For more information, see the [GitHub Wiki](https://github.com/ArthurHub/Android
124124
*2.5.1* (in-dev)
125125
- Try solve manifest merger issue by adding `transitive` flag #405 (thx @j-garin)
126126
- Use thread pool executors for async image loading and cropping operations to prevent app hang if default executor is busy (thx @ruifcardoso)
127+
- Fix image rotation breaking min/max crop result restrictions #401
127128

128129
*2.5.0*
129130
- Update to sdk v26

cropper/src/main/java/com/theartofdev/edmodo/cropper/BitmapUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ static float getRectWidth(float[] points) {
308308
return getRectRight(points) - getRectLeft(points);
309309
}
310310

311-
/** Get heightof the bounding rectangle of the given points. */
311+
/** Get height of the bounding rectangle of the given points. */
312312
static float getRectHeight(float[] points) {
313313
return getRectBottom(points) - getRectTop(points);
314314
}
@@ -318,7 +318,7 @@ static float getRectCenterX(float[] points) {
318318
return (getRectRight(points) + getRectLeft(points)) / 2f;
319319
}
320320

321-
/** Get verical center value of the bounding rectangle of the given points. */
321+
/** Get vertical center value of the bounding rectangle of the given points. */
322322
static float getRectCenterY(float[] points) {
323323
return (getRectBottom(points) + getRectTop(points)) / 2f;
324324
}

cropper/src/main/java/com/theartofdev/edmodo/cropper/CropImageView.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,12 @@ public class CropImageView extends FrameLayout {
5858
/** Progress bar widget to show progress bar on async image loading and cropping. */
5959
private final ProgressBar mProgressBar;
6060

61-
/** Rectengale used in image matrix transformation calculation (reusing rect instance) */
61+
/** Rectangle used in image matrix transformation calculation (reusing rect instance) */
6262
private final float[] mImagePoints = new float[8];
6363

64+
/** Rectangle used in image matrix transformation for scale calculation (reusing rect instance) */
65+
private final float[] mScaleImagePoints = new float[8];
66+
6467
/** Animation class to smooth animate zoom-in/out */
6568
private CropImageAnimation mAnimation;
6669

@@ -323,10 +326,10 @@ public CropImageView(Context context, AttributeSet attrs) {
323326
LayoutInflater inflater = LayoutInflater.from(context);
324327
View v = inflater.inflate(R.layout.crop_image_view, this, true);
325328

326-
mImageView = (ImageView) v.findViewById(R.id.ImageView_image);
329+
mImageView = v.findViewById(R.id.ImageView_image);
327330
mImageView.setScaleType(ImageView.ScaleType.MATRIX);
328331

329-
mCropOverlayView = (CropOverlayView) v.findViewById(R.id.CropOverlayView);
332+
mCropOverlayView = v.findViewById(R.id.CropOverlayView);
330333
mCropOverlayView.setCropWindowChangeListener(
331334
new CropOverlayView.CropWindowChangeListener() {
332335
@Override
@@ -344,7 +347,7 @@ public void onCropWindowChanged(boolean inProgress) {
344347
});
345348
mCropOverlayView.setInitialAttributeValues(options);
346349

347-
mProgressBar = (ProgressBar) v.findViewById(R.id.CropProgressBar);
350+
mProgressBar = v.findViewById(R.id.CropProgressBar);
348351
setProgressBarVisibility();
349352
}
350353

@@ -1727,7 +1730,7 @@ private void applyImageMatrix(float width, float height, boolean center, boolean
17271730
/**
17281731
* Adjust the given image rectangle by image transformation matrix to know the final rectangle of
17291732
* the image.<br>
1730-
* To get the proper rectangle it must be first reset to orginal image rectangle.
1733+
* To get the proper rectangle it must be first reset to original image rectangle.
17311734
*/
17321735
private void mapImagePointsByImageMatrix() {
17331736
mImagePoints[0] = 0;
@@ -1739,6 +1742,15 @@ private void mapImagePointsByImageMatrix() {
17391742
mImagePoints[6] = 0;
17401743
mImagePoints[7] = mBitmap.getHeight();
17411744
mImageMatrix.mapPoints(mImagePoints);
1745+
mScaleImagePoints[0] = 0;
1746+
mScaleImagePoints[1] = 0;
1747+
mScaleImagePoints[2] = 100;
1748+
mScaleImagePoints[3] = 0;
1749+
mScaleImagePoints[4] = 100;
1750+
mScaleImagePoints[5] = 100;
1751+
mScaleImagePoints[6] = 0;
1752+
mScaleImagePoints[7] = 100;
1753+
mImageMatrix.mapPoints(mScaleImagePoints);
17421754
}
17431755

17441756
/**
@@ -1795,9 +1807,9 @@ private void updateImageBounds(boolean clear) {
17951807
// Get the scale factor between the actual Bitmap dimensions and the displayed dimensions for
17961808
// width/height.
17971809
float scaleFactorWidth =
1798-
mBitmap.getWidth() * mLoadedSampleSize / BitmapUtils.getRectWidth(mImagePoints);
1810+
100f * mLoadedSampleSize / BitmapUtils.getRectWidth(mScaleImagePoints);
17991811
float scaleFactorHeight =
1800-
mBitmap.getHeight() * mLoadedSampleSize / BitmapUtils.getRectHeight(mImagePoints);
1812+
100f * mLoadedSampleSize / BitmapUtils.getRectHeight(mScaleImagePoints);
18011813
mCropOverlayView.setCropWindowLimits(
18021814
getWidth(), getHeight(), scaleFactorWidth, scaleFactorHeight);
18031815
}

sample/src/main/java/com/theartofdev/edmodo/cropper/sample/MainFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public View onCreateView(
132132
public void onViewCreated(View view, Bundle savedInstanceState) {
133133
super.onViewCreated(view, savedInstanceState);
134134

135-
mCropImageView = (CropImageView) view.findViewById(R.id.cropImageView);
135+
mCropImageView = view.findViewById(R.id.cropImageView);
136136
mCropImageView.setOnSetImageUriCompleteListener(this);
137137
mCropImageView.setOnCropImageCompleteListener(this);
138138

0 commit comments

Comments
 (0)