Open markxh opened 7 years ago
I am waiting for this fix too.
maybe help ?
/**
* Handle scaling the rectangle based on two finger input
*/
private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public boolean onScale(ScaleGestureDetector detector) {
RectF rect = mCropWindowHandler.getRect();
float scaleFactor = detector.getScaleFactor();
scaleFactor = Math.max(0.5f, Math.min(scaleFactor, 1.5f));
float width = rect.width();
float height = rect.height();
float newWidth = rect.width() * scaleFactor;
float newHeight = rect.height() * scaleFactor;
float originCenterX = (rect.left + rect.right) / 2;
float originCenterY = (rect.top + rect.bottom) / 2;
float x = detector.getFocusX();
float y = detector.getFocusY();
float dY = detector.getCurrentSpanY() / 2;
float dX = detector.getCurrentSpanX() / 2;
float newTop = originCenterY - newHeight / 2;
float newLeft = originCenterX - newWidth / 2;
float newRight = originCenterX + newWidth / 2;
float newBottom = originCenterY + newHeight / 2;
if (newLeft < newRight &&
newTop <= newBottom &&
newLeft >= 0 &&
newWidth <= mCropWindowHandler.getMaxCropWidth() &&
newTop >= 0 &&
newHeight <= mCropWindowHandler.getMaxCropHeight()) {
rect.set(newLeft, newTop, newRight, newBottom);
mCropWindowHandler.setRect(rect);
invalidate();
}
return true;
}
}
I have the same issue.
Same for me
@klob This is my solution:
/**
* Handle scaling the rectangle based on two finger input
*/
private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public boolean onScale(ScaleGestureDetector detector) {
RectF rect = mCropWindowHandler.getRect();
float scaleFactor = detector.getScaleFactor();
scaleFactor = Math.max(0.5f, Math.min(scaleFactor, 1.5f));
float width = rect.width();
float height = rect.height();
float newWidth = rect.width() * scaleFactor;
float newHeight = rect.height() * scaleFactor;
float originCenterX = (rect.left + rect.right) / 2;
float originCenterY = (rect.top + rect.bottom) / 2;
float x = detector.getFocusX();
float y = detector.getFocusY();
float dY = detector.getCurrentSpanY() / 2;
float dX = detector.getCurrentSpanX() / 2;
float bitmapTop = Math.max(0, BitmapUtils.getRectTop(mBoundsPoints)); //top border
float bitmapLeft = Math.max(0, BitmapUtils.getRectLeft(mBoundsPoints)); //left border
float bitmapRight = Math.min(getWidth(), BitmapUtils.getRectRight(mBoundsPoints)); //right border
float bitmapBottom = Math.min(getHeight(), BitmapUtils.getRectBottom(mBoundsPoints)); //bottom border
float newTop = Math.max(bitmapTop, originCenterY - newHeight / 2);
float newLeft = Math.max(bitmapLeft, originCenterX - newWidth / 2);
float newRight = Math.min(bitmapRight, originCenterX + newWidth / 2);
float newBottom = Math.min(bitmapBottom, originCenterY + newHeight / 2);
newWidth = newRight - newLeft;
newHeight = newBottom - newTop;
if (newLeft < newRight &&
newTop < newBottom &&
newWidth <= mCropWindowHandler.getMaxCropWidth() &&
newWidth >= mCropWindowHandler.getMinCropWidth() &&
newHeight <= mCropWindowHandler.getMaxCropHeight() &&
newHeight >= mCropWindowHandler.getMinCropHeight()) {
rect.set(newLeft, newTop, newRight, newBottom);
mCropWindowHandler.setRect(rect);
invalidate();
}
return true;
}
}
Any updates here?
When multti touch is enabled to pinch-zoom, the Aspect Ratio does not persist.