diff --git a/README.md b/README.md index 8095021f..03382ad4 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Android Image Cropper 1. Include the library ``` - compile 'com.theartofdev.edmodo:android-image-cropper:2.4.+' + compile 'com.theartofdev.edmodo:android-image-cropper:2.5.+' ``` Add permissions to manifest diff --git a/cropper/src/main/java/com/theartofdev/edmodo/cropper/CropImageActivity.java b/cropper/src/main/java/com/theartofdev/edmodo/cropper/CropImageActivity.java index 369cb45e..979b368c 100644 --- a/cropper/src/main/java/com/theartofdev/edmodo/cropper/CropImageActivity.java +++ b/cropper/src/main/java/com/theartofdev/edmodo/cropper/CropImageActivity.java @@ -61,7 +61,7 @@ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.crop_image_activity); - mCropImageView = (CropImageView) findViewById(R.id.cropImageView); + mCropImageView = findViewById(R.id.cropImageView); Bundle bundle = getIntent().getBundleExtra(CropImageOptions.BUNDLE_KEY); mCropImageUri = bundle.getParcelable(CropImage.CROP_IMAGE_EXTRA_SOURCE); diff --git a/cropper/src/main/java/com/theartofdev/edmodo/cropper/CropImageView.java b/cropper/src/main/java/com/theartofdev/edmodo/cropper/CropImageView.java index f275bfe1..f30aaa8d 100644 --- a/cropper/src/main/java/com/theartofdev/edmodo/cropper/CropImageView.java +++ b/cropper/src/main/java/com/theartofdev/edmodo/cropper/CropImageView.java @@ -622,12 +622,14 @@ public Uri getImageUri() { * @return a Rect instance dimensions of the source Bitmap */ public Rect getWholeImageRect() { - if (mBitmap == null) { + int loadedSampleSize = mLoadedSampleSize; + Bitmap bitmap = mBitmap; + if (bitmap == null) { return null; } - - int orgWidth = mBitmap.getWidth() * mLoadedSampleSize; - int orgHeight = mBitmap.getHeight() * mLoadedSampleSize; + + int orgWidth = bitmap.getWidth() * loadedSampleSize; + int orgHeight = bitmap.getHeight() * loadedSampleSize; return new Rect(0, 0, orgWidth, orgHeight); } @@ -638,20 +640,21 @@ public Rect getWholeImageRect() { * @return a Rect instance containing cropped area boundaries of the source Bitmap */ public Rect getCropRect() { - if (mBitmap != null) { + int loadedSampleSize = mLoadedSampleSize; + Bitmap bitmap = mBitmap; + if (bitmap == null) { + return null; + } - // get the points of the crop rectangle adjusted to source bitmap - float[] points = getCropPoints(); + // get the points of the crop rectangle adjusted to source bitmap + float[] points = getCropPoints(); - int orgWidth = mBitmap.getWidth() * mLoadedSampleSize; - int orgHeight = mBitmap.getHeight() * mLoadedSampleSize; + int orgWidth = bitmap.getWidth() * loadedSampleSize; + int orgHeight = bitmap.getHeight() * loadedSampleSize; - // get the rectangle for the points (it may be larger than original if rotation is not stright) - return BitmapUtils.getRectFromPoints(points, orgWidth, orgHeight, - mCropOverlayView.isFixAspectRatio(), mCropOverlayView.getAspectRatioX(), mCropOverlayView.getAspectRatioY()); - } else { - return null; - } + // get the rectangle for the points (it may be larger than original if rotation is not stright) + return BitmapUtils.getRectFromPoints(points, orgWidth, orgHeight, + mCropOverlayView.isFixAspectRatio(), mCropOverlayView.getAspectRatioX(), mCropOverlayView.getAspectRatioY()); } /** @@ -1161,7 +1164,8 @@ private void clearImageInt() { * @param saveCompressQuality if saveUri is given, the given quality will be used for the compression. */ public void startCropWorkerTask(int reqWidth, int reqHeight, RequestSizeOptions options, Uri saveUri, Bitmap.CompressFormat saveCompressFormat, int saveCompressQuality) { - if (mBitmap != null) { + Bitmap bitmap = mBitmap; + if (bitmap != null) { mImageView.clearAnimation(); BitmapCroppingWorkerTask currentTask = mBitmapCroppingWorkerTask != null ? mBitmapCroppingWorkerTask.get() : null; @@ -1173,8 +1177,8 @@ public void startCropWorkerTask(int reqWidth, int reqHeight, RequestSizeOptions reqWidth = options != RequestSizeOptions.NONE ? reqWidth : 0; reqHeight = options != RequestSizeOptions.NONE ? reqHeight : 0; - int orgWidth = mBitmap.getWidth() * mLoadedSampleSize; - int orgHeight = mBitmap.getHeight() * mLoadedSampleSize; + int orgWidth = bitmap.getWidth() * mLoadedSampleSize; + int orgHeight = bitmap.getHeight() * mLoadedSampleSize; if (mLoadedImageUri != null && (mLoadedSampleSize > 1 || options == RequestSizeOptions.SAMPLING)) { mBitmapCroppingWorkerTask = new WeakReference<>(new BitmapCroppingWorkerTask(this, mLoadedImageUri, getCropPoints(), mDegreesRotated, orgWidth, orgHeight, @@ -1182,7 +1186,7 @@ public void startCropWorkerTask(int reqWidth, int reqHeight, RequestSizeOptions reqWidth, reqHeight, mFlipHorizontally, mFlipVertically, options, saveUri, saveCompressFormat, saveCompressQuality)); } else { - mBitmapCroppingWorkerTask = new WeakReference<>(new BitmapCroppingWorkerTask(this, mBitmap, getCropPoints(), mDegreesRotated, + mBitmapCroppingWorkerTask = new WeakReference<>(new BitmapCroppingWorkerTask(this, bitmap, getCropPoints(), mDegreesRotated, mCropOverlayView.isFixAspectRatio(), mCropOverlayView.getAspectRatioX(), mCropOverlayView.getAspectRatioY(), reqWidth, reqHeight, mFlipHorizontally, mFlipVertically, options, saveUri, saveCompressFormat, saveCompressQuality));