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

Show output image width and height when crop area is selected in CropView #204

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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 @@ -53,19 +53,19 @@ public class CropImageActivity extends MonitoredActivity {
private int aspectY;

// Output image
private int maxX;
private int maxY;
protected int maxX;
protected int maxY;
private int exifRotation;

private Uri sourceUri;
private Uri saveUri;

private boolean isSaving;

private int sampleSize;
protected int sampleSize;
private RotateBitmap rotateBitmap;
private CropImageView imageView;
private HighlightView cropView;
protected HighlightView cropView;

@Override
public void onCreate(Bundle icicle) {
Expand Down
20 changes: 20 additions & 0 deletions lib/src/main/java/com/soundcloud/android/crop/CropImageView.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.Toast;

import java.util.ArrayList;

Expand Down Expand Up @@ -115,6 +116,25 @@ public boolean onTouchEvent(@NonNull MotionEvent event) {
}
motionHighlightView = null;
center();

CropImageActivity cia=(CropImageActivity)context;
Rect r=cia.cropView.getScaledCropRect(cia.sampleSize);
int width = r.width();
int height = r.height();
int outWidth = width;
int outHeight = height;
if (cia.maxX > 0 && cia.maxY > 0 && (width > cia.maxX || height > cia.maxY)) {
float ratio = (float) width / (float) height;
if ((float) cia.maxX / (float) cia.maxY > ratio) {
outHeight = cia.maxY;
outWidth = (int) ((float) cia.maxY * ratio + .5f);
} else {
outWidth = cia.maxX;
outHeight = (int) ((float) cia.maxX / ratio + .5f);
}
}
Toast t=Toast.makeText(cia, outWidth + "x" + outHeight, Toast.LENGTH_SHORT);
t.show();
break;
case MotionEvent.ACTION_MOVE:
if (motionHighlightView != null && event.getPointerId(event.getActionIndex()) == validPointerId) {
Expand Down