Skip to content
This repository has been archived by the owner on Jan 7, 2023. It is now read-only.

Returns bounds into intent #138

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ private void onSaveClicked() {
isSaving = true;

Bitmap croppedImage;
Rect r = cropView.getScaledCropRect(sampleSize);
int width = r.width();
int height = r.height();
Rect scaledCropRect = cropView.getScaledCropRect(sampleSize);
int width = scaledCropRect.width();
int height = scaledCropRect.height();

int outWidth = width;
int outHeight = height;
Expand All @@ -275,7 +275,7 @@ private void onSaveClicked() {
}

try {
croppedImage = decodeRegionCrop(r, outWidth, outHeight);
croppedImage = decodeRegionCrop(scaledCropRect, outWidth, outHeight);
} catch (IllegalArgumentException e) {
setResultException(e);
finish();
Expand All @@ -287,16 +287,16 @@ private void onSaveClicked() {
imageView.center(true, true);
imageView.highlightViews.clear();
}
saveImage(croppedImage);
saveImage(croppedImage, scaledCropRect);
}

private void saveImage(Bitmap croppedImage) {
private void saveImage(Bitmap croppedImage, final Rect scaledCropRect) {
if (croppedImage != null) {
final Bitmap b = croppedImage;
CropUtil.startBackgroundJob(this, null, getResources().getString(R.string.crop__saving),
new Runnable() {
public void run() {
saveOutput(b);
saveOutput(b, scaledCropRect);
}
}, handler
);
Expand Down Expand Up @@ -363,7 +363,7 @@ private void clearImageView() {
System.gc();
}

private void saveOutput(Bitmap croppedImage) {
private void saveOutput(Bitmap croppedImage, Rect scaledCropRect) {
if (saveUri != null) {
OutputStream outputStream = null;
try {
Expand All @@ -383,7 +383,7 @@ private void saveOutput(Bitmap croppedImage) {
CropUtil.getFromMediaUri(this, getContentResolver(), saveUri)
);

setResultUri(saveUri);
setResultUri(saveUri, scaledCropRect);
}

final Bitmap b = croppedImage;
Expand Down Expand Up @@ -414,8 +414,11 @@ public boolean isSaving() {
return isSaving;
}

private void setResultUri(Uri uri) {
setResult(RESULT_OK, new Intent().putExtra(MediaStore.EXTRA_OUTPUT, uri));
private void setResultUri(Uri uri, Rect scaledCropRect) {
Intent intent = new Intent();
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
intent.putExtra(Crop.BOUNDS, scaledCropRect);
setResult(RESULT_OK, intent);
}

private void setResultException(Throwable throwable) {
Expand Down