Skip to content

Commit

Permalink
fix image rotation breaking min/max crop result restrictions #401
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurHub committed Oct 7, 2017
1 parent 2726e5e commit 0e923fc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ For more information, see the [GitHub Wiki](https://github.com/ArthurHub/Android
*2.5.1* (in-dev)
- Try solve manifest merger issue by adding `transitive` flag #405 (thx @j-garin)
- Use thread pool executors for async image loading and cropping operations to prevent app hang if default executor is busy (thx @ruifcardoso)
- Fix image rotation breaking min/max crop result restrictions #401

*2.5.0*
- Update to sdk v26
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ static float getRectWidth(float[] points) {
return getRectRight(points) - getRectLeft(points);
}

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

/** Get verical center value of the bounding rectangle of the given points. */
/** Get vertical center value of the bounding rectangle of the given points. */
static float getRectCenterY(float[] points) {
return (getRectBottom(points) + getRectTop(points)) / 2f;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ public class CropImageView extends FrameLayout {
/** Progress bar widget to show progress bar on async image loading and cropping. */
private final ProgressBar mProgressBar;

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

/** Rectangle used in image matrix transformation for scale calculation (reusing rect instance) */
private final float[] mScaleImagePoints = new float[8];

/** Animation class to smooth animate zoom-in/out */
private CropImageAnimation mAnimation;

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

mImageView = (ImageView) v.findViewById(R.id.ImageView_image);
mImageView = v.findViewById(R.id.ImageView_image);
mImageView.setScaleType(ImageView.ScaleType.MATRIX);

mCropOverlayView = (CropOverlayView) v.findViewById(R.id.CropOverlayView);
mCropOverlayView = v.findViewById(R.id.CropOverlayView);
mCropOverlayView.setCropWindowChangeListener(
new CropOverlayView.CropWindowChangeListener() {
@Override
Expand All @@ -344,7 +347,7 @@ public void onCropWindowChanged(boolean inProgress) {
});
mCropOverlayView.setInitialAttributeValues(options);

mProgressBar = (ProgressBar) v.findViewById(R.id.CropProgressBar);
mProgressBar = v.findViewById(R.id.CropProgressBar);
setProgressBarVisibility();
}

Expand Down Expand Up @@ -1727,7 +1730,7 @@ private void applyImageMatrix(float width, float height, boolean center, boolean
/**
* Adjust the given image rectangle by image transformation matrix to know the final rectangle of
* the image.<br>
* To get the proper rectangle it must be first reset to orginal image rectangle.
* To get the proper rectangle it must be first reset to original image rectangle.
*/
private void mapImagePointsByImageMatrix() {
mImagePoints[0] = 0;
Expand All @@ -1739,6 +1742,15 @@ private void mapImagePointsByImageMatrix() {
mImagePoints[6] = 0;
mImagePoints[7] = mBitmap.getHeight();
mImageMatrix.mapPoints(mImagePoints);
mScaleImagePoints[0] = 0;
mScaleImagePoints[1] = 0;
mScaleImagePoints[2] = 100;
mScaleImagePoints[3] = 0;
mScaleImagePoints[4] = 100;
mScaleImagePoints[5] = 100;
mScaleImagePoints[6] = 0;
mScaleImagePoints[7] = 100;
mImageMatrix.mapPoints(mScaleImagePoints);
}

/**
Expand Down Expand Up @@ -1795,9 +1807,9 @@ private void updateImageBounds(boolean clear) {
// Get the scale factor between the actual Bitmap dimensions and the displayed dimensions for
// width/height.
float scaleFactorWidth =
mBitmap.getWidth() * mLoadedSampleSize / BitmapUtils.getRectWidth(mImagePoints);
100f * mLoadedSampleSize / BitmapUtils.getRectWidth(mScaleImagePoints);
float scaleFactorHeight =
mBitmap.getHeight() * mLoadedSampleSize / BitmapUtils.getRectHeight(mImagePoints);
100f * mLoadedSampleSize / BitmapUtils.getRectHeight(mScaleImagePoints);
mCropOverlayView.setCropWindowLimits(
getWidth(), getHeight(), scaleFactorWidth, scaleFactorHeight);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public View onCreateView(
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

mCropImageView = (CropImageView) view.findViewById(R.id.cropImageView);
mCropImageView = view.findViewById(R.id.cropImageView);
mCropImageView.setOnSetImageUriCompleteListener(this);
mCropImageView.setOnCropImageCompleteListener(this);

Expand Down

0 comments on commit 0e923fc

Please sign in to comment.