Skip to content

Commit d5c5cbc

Browse files
committed
fix ver doc and minor refactor
1 parent a46d434 commit d5c5cbc

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Android Image Cropper
1717
1. Include the library
1818

1919
```
20-
compile 'com.theartofdev.edmodo:android-image-cropper:2.4.+'
20+
compile 'com.theartofdev.edmodo:android-image-cropper:2.5.+'
2121
```
2222

2323
Add permissions to manifest

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void onCreate(Bundle savedInstanceState) {
6161
super.onCreate(savedInstanceState);
6262
setContentView(R.layout.crop_image_activity);
6363

64-
mCropImageView = (CropImageView) findViewById(R.id.cropImageView);
64+
mCropImageView = findViewById(R.id.cropImageView);
6565

6666
Bundle bundle = getIntent().getBundleExtra(CropImageOptions.BUNDLE_KEY);
6767
mCropImageUri = bundle.getParcelable(CropImage.CROP_IMAGE_EXTRA_SOURCE);

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

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -622,12 +622,14 @@ public Uri getImageUri() {
622622
* @return a Rect instance dimensions of the source Bitmap
623623
*/
624624
public Rect getWholeImageRect() {
625-
if (mBitmap == null) {
625+
int loadedSampleSize = mLoadedSampleSize;
626+
Bitmap bitmap = mBitmap;
627+
if (bitmap == null) {
626628
return null;
627629
}
628-
629-
int orgWidth = mBitmap.getWidth() * mLoadedSampleSize;
630-
int orgHeight = mBitmap.getHeight() * mLoadedSampleSize;
630+
631+
int orgWidth = bitmap.getWidth() * loadedSampleSize;
632+
int orgHeight = bitmap.getHeight() * loadedSampleSize;
631633
return new Rect(0, 0, orgWidth, orgHeight);
632634
}
633635

@@ -638,20 +640,21 @@ public Rect getWholeImageRect() {
638640
* @return a Rect instance containing cropped area boundaries of the source Bitmap
639641
*/
640642
public Rect getCropRect() {
641-
if (mBitmap != null) {
643+
int loadedSampleSize = mLoadedSampleSize;
644+
Bitmap bitmap = mBitmap;
645+
if (bitmap == null) {
646+
return null;
647+
}
642648

643-
// get the points of the crop rectangle adjusted to source bitmap
644-
float[] points = getCropPoints();
649+
// get the points of the crop rectangle adjusted to source bitmap
650+
float[] points = getCropPoints();
645651

646-
int orgWidth = mBitmap.getWidth() * mLoadedSampleSize;
647-
int orgHeight = mBitmap.getHeight() * mLoadedSampleSize;
652+
int orgWidth = bitmap.getWidth() * loadedSampleSize;
653+
int orgHeight = bitmap.getHeight() * loadedSampleSize;
648654

649-
// get the rectangle for the points (it may be larger than original if rotation is not stright)
650-
return BitmapUtils.getRectFromPoints(points, orgWidth, orgHeight,
651-
mCropOverlayView.isFixAspectRatio(), mCropOverlayView.getAspectRatioX(), mCropOverlayView.getAspectRatioY());
652-
} else {
653-
return null;
654-
}
655+
// get the rectangle for the points (it may be larger than original if rotation is not stright)
656+
return BitmapUtils.getRectFromPoints(points, orgWidth, orgHeight,
657+
mCropOverlayView.isFixAspectRatio(), mCropOverlayView.getAspectRatioX(), mCropOverlayView.getAspectRatioY());
655658
}
656659

657660
/**
@@ -1161,7 +1164,8 @@ private void clearImageInt() {
11611164
* @param saveCompressQuality if saveUri is given, the given quality will be used for the compression.
11621165
*/
11631166
public void startCropWorkerTask(int reqWidth, int reqHeight, RequestSizeOptions options, Uri saveUri, Bitmap.CompressFormat saveCompressFormat, int saveCompressQuality) {
1164-
if (mBitmap != null) {
1167+
Bitmap bitmap = mBitmap;
1168+
if (bitmap != null) {
11651169
mImageView.clearAnimation();
11661170

11671171
BitmapCroppingWorkerTask currentTask = mBitmapCroppingWorkerTask != null ? mBitmapCroppingWorkerTask.get() : null;
@@ -1173,16 +1177,16 @@ public void startCropWorkerTask(int reqWidth, int reqHeight, RequestSizeOptions
11731177
reqWidth = options != RequestSizeOptions.NONE ? reqWidth : 0;
11741178
reqHeight = options != RequestSizeOptions.NONE ? reqHeight : 0;
11751179

1176-
int orgWidth = mBitmap.getWidth() * mLoadedSampleSize;
1177-
int orgHeight = mBitmap.getHeight() * mLoadedSampleSize;
1180+
int orgWidth = bitmap.getWidth() * mLoadedSampleSize;
1181+
int orgHeight = bitmap.getHeight() * mLoadedSampleSize;
11781182
if (mLoadedImageUri != null && (mLoadedSampleSize > 1 || options == RequestSizeOptions.SAMPLING)) {
11791183
mBitmapCroppingWorkerTask = new WeakReference<>(new BitmapCroppingWorkerTask(this, mLoadedImageUri, getCropPoints(),
11801184
mDegreesRotated, orgWidth, orgHeight,
11811185
mCropOverlayView.isFixAspectRatio(), mCropOverlayView.getAspectRatioX(), mCropOverlayView.getAspectRatioY(),
11821186
reqWidth, reqHeight, mFlipHorizontally, mFlipVertically, options,
11831187
saveUri, saveCompressFormat, saveCompressQuality));
11841188
} else {
1185-
mBitmapCroppingWorkerTask = new WeakReference<>(new BitmapCroppingWorkerTask(this, mBitmap, getCropPoints(), mDegreesRotated,
1189+
mBitmapCroppingWorkerTask = new WeakReference<>(new BitmapCroppingWorkerTask(this, bitmap, getCropPoints(), mDegreesRotated,
11861190
mCropOverlayView.isFixAspectRatio(), mCropOverlayView.getAspectRatioX(), mCropOverlayView.getAspectRatioY(),
11871191
reqWidth, reqHeight, mFlipHorizontally, mFlipVertically, options,
11881192
saveUri, saveCompressFormat, saveCompressQuality));

0 commit comments

Comments
 (0)