diff --git a/build.gradle b/build.gradle index 587fbc51d..09d666277 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.0' + classpath 'com.android.tools.build:gradle:2.3.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/ucrop/src/main/java/com/yalantis/ucrop/UCrop.java b/ucrop/src/main/java/com/yalantis/ucrop/UCrop.java index a01acf923..f8cc9369e 100644 --- a/ucrop/src/main/java/com/yalantis/ucrop/UCrop.java +++ b/ucrop/src/main/java/com/yalantis/ucrop/UCrop.java @@ -40,6 +40,8 @@ public class UCrop { public static final String EXTRA_OUTPUT_CROP_ASPECT_RATIO = EXTRA_PREFIX + ".CropAspectRatio"; public static final String EXTRA_OUTPUT_IMAGE_WIDTH = EXTRA_PREFIX + ".ImageWidth"; public static final String EXTRA_OUTPUT_IMAGE_HEIGHT = EXTRA_PREFIX + ".ImageHeight"; + public static final String EXTRA_OUTPUT_OFFSET_X = EXTRA_PREFIX + ".OffsetX"; + public static final String EXTRA_OUTPUT_OFFSET_Y = EXTRA_PREFIX + ".OffsetY"; public static final String EXTRA_ERROR = EXTRA_PREFIX + ".Error"; public static final String EXTRA_ASPECT_RATIO_X = EXTRA_PREFIX + ".AspectRatioX"; diff --git a/ucrop/src/main/java/com/yalantis/ucrop/UCropActivity.java b/ucrop/src/main/java/com/yalantis/ucrop/UCropActivity.java index 2f71291ff..5067db44b 100644 --- a/ucrop/src/main/java/com/yalantis/ucrop/UCropActivity.java +++ b/ucrop/src/main/java/com/yalantis/ucrop/UCropActivity.java @@ -612,8 +612,8 @@ protected void cropAndSaveImage() { mGestureCropImageView.cropAndSaveImage(mCompressFormat, mCompressQuality, new BitmapCropCallback() { @Override - public void onBitmapCropped(@NonNull Uri resultUri, int imageWidth, int imageHeight) { - setResultUri(resultUri, mGestureCropImageView.getTargetAspectRatio(), imageWidth, imageHeight); + public void onBitmapCropped(@NonNull Uri resultUri, int offsetX, int offsetY, int imageWidth, int imageHeight) { + setResultUri(resultUri, mGestureCropImageView.getTargetAspectRatio(), offsetX, offsetY, imageWidth, imageHeight); finish(); } @@ -625,12 +625,14 @@ public void onCropFailure(@NonNull Throwable t) { }); } - protected void setResultUri(Uri uri, float resultAspectRatio, int imageWidth, int imageHeight) { + protected void setResultUri(Uri uri, float resultAspectRatio, int offsetX, int offsetY, int imageWidth, int imageHeight) { setResult(RESULT_OK, new Intent() .putExtra(UCrop.EXTRA_OUTPUT_URI, uri) .putExtra(UCrop.EXTRA_OUTPUT_CROP_ASPECT_RATIO, resultAspectRatio) .putExtra(UCrop.EXTRA_OUTPUT_IMAGE_WIDTH, imageWidth) .putExtra(UCrop.EXTRA_OUTPUT_IMAGE_HEIGHT, imageHeight) + .putExtra(UCrop.EXTRA_OUTPUT_OFFSET_X, offsetX) + .putExtra(UCrop.EXTRA_OUTPUT_OFFSET_Y, offsetY) ); } diff --git a/ucrop/src/main/java/com/yalantis/ucrop/callback/BitmapCropCallback.java b/ucrop/src/main/java/com/yalantis/ucrop/callback/BitmapCropCallback.java index 3e4b23a6c..afe82e43d 100644 --- a/ucrop/src/main/java/com/yalantis/ucrop/callback/BitmapCropCallback.java +++ b/ucrop/src/main/java/com/yalantis/ucrop/callback/BitmapCropCallback.java @@ -5,7 +5,7 @@ public interface BitmapCropCallback { - void onBitmapCropped(@NonNull Uri resultUri, int imageWidth, int imageHeight); + void onBitmapCropped(@NonNull Uri resultUri, int offsetX, int offsetY, int imageWidth, int imageHeight); void onCropFailure(@NonNull Throwable t); diff --git a/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapCropTask.java b/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapCropTask.java index efc0178e4..5429bb37c 100644 --- a/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapCropTask.java +++ b/ucrop/src/main/java/com/yalantis/ucrop/task/BitmapCropTask.java @@ -50,6 +50,7 @@ public class BitmapCropTask extends AsyncTask { private final BitmapCropCallback mCropCallback; private int mCroppedImageWidth, mCroppedImageHeight; + private int cropOffsetX, cropOffsetY; public BitmapCropTask(@Nullable Bitmap viewBitmap, @NonNull ImageState imageState, @NonNull CropParameters cropParameters, @Nullable BitmapCropCallback cropCallback) { @@ -129,8 +130,8 @@ private float resize() { private boolean crop(float resizeScale) throws IOException { ExifInterface originalExif = new ExifInterface(mImageInputPath); - int top = Math.round((mCropRect.top - mCurrentImageRect.top) / mCurrentScale); - int left = Math.round((mCropRect.left - mCurrentImageRect.left) / mCurrentScale); + cropOffsetX = Math.round((mCropRect.left - mCurrentImageRect.left) / mCurrentScale); + cropOffsetY = Math.round((mCropRect.top - mCurrentImageRect.top) / mCurrentScale); mCroppedImageWidth = Math.round(mCropRect.width() / mCurrentScale); mCroppedImageHeight = Math.round(mCropRect.height() / mCurrentScale); @@ -139,8 +140,8 @@ private boolean crop(float resizeScale) throws IOException { if (shouldCrop) { boolean cropped = cropCImg(mImageInputPath, mImageOutputPath, - left, top, mCroppedImageWidth, mCroppedImageHeight, mCurrentAngle, resizeScale, - mCompressFormat.ordinal(), mCompressQuality, + cropOffsetX, cropOffsetY, mCroppedImageWidth, mCroppedImageHeight, + mCurrentAngle, resizeScale, mCompressFormat.ordinal(), mCompressQuality, mExifInfo.getExifDegrees(), mExifInfo.getExifTranslation()); if (cropped && mCompressFormat.equals(Bitmap.CompressFormat.JPEG)) { ImageHeaderParser.copyExif(originalExif, mCroppedImageWidth, mCroppedImageHeight, mImageOutputPath); @@ -182,7 +183,8 @@ private boolean shouldCrop(int width, int height) { protected void onPostExecute(@Nullable Throwable t) { if (mCropCallback != null) { if (t == null) { - mCropCallback.onBitmapCropped(Uri.fromFile(new File(mImageOutputPath)), mCroppedImageWidth, mCroppedImageHeight); + Uri uri = Uri.fromFile(new File(mImageOutputPath)); + mCropCallback.onBitmapCropped(uri, cropOffsetX, cropOffsetY, mCroppedImageWidth, mCroppedImageHeight); } else { mCropCallback.onCropFailure(t); }