修复剪裁窗口画布控件缩放和布局问题
- 修复ZoomContainerView缩放按钮无效问题,添加onLayout正确缩放子视图 - 修复CropCanvasView裁剪框显示不一致问题 - 更新libappbase版本到15.15.20 - 优化剪裁窗口布局
This commit is contained in:
@@ -221,8 +221,30 @@ public class CropCanvasView extends View {
|
||||
}
|
||||
|
||||
public void scaleToView(int viewWidth, int viewHeight) {
|
||||
requestLayout();
|
||||
invalidate();
|
||||
if (viewWidth > 0 && viewHeight > 0 && canvasWidth > 0 && canvasHeight > 0) {
|
||||
float scale = Math.max((float) viewWidth / canvasWidth, (float) viewHeight / canvasHeight);
|
||||
int oldCanvasW = canvasWidth;
|
||||
int oldCanvasH = canvasHeight;
|
||||
canvasWidth = (int) (canvasWidth * scale);
|
||||
canvasHeight = (int) (canvasHeight * scale);
|
||||
|
||||
float left = (canvasWidth - imageWidth) / 2f;
|
||||
float top = (canvasHeight - imageHeight) / 2f;
|
||||
imageBounds.set(left, top, left + imageWidth, top + imageHeight);
|
||||
canvasBounds.set(0, 0, canvasWidth, canvasHeight);
|
||||
|
||||
if (cropRect != null) {
|
||||
float scaleX = (float) canvasWidth / oldCanvasW;
|
||||
float scaleY = (float) canvasHeight / oldCanvasH;
|
||||
cropRect.left *= scaleX;
|
||||
cropRect.top *= scaleY;
|
||||
cropRect.right *= scaleX;
|
||||
cropRect.bottom *= scaleY;
|
||||
}
|
||||
|
||||
requestLayout();
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public RectF getCropRect() {
|
||||
@@ -295,15 +317,10 @@ public class CropCanvasView extends View {
|
||||
canvas.restore();
|
||||
|
||||
canvas.drawRect(cropRect, borderPaint);
|
||||
|
||||
float scX = imageToScreenX(cropRect.left);
|
||||
float scY = imageToScreenY(cropRect.top);
|
||||
float scR = imageToScreenX(cropRect.right);
|
||||
float scB = imageToScreenY(cropRect.bottom);
|
||||
canvas.drawCircle(scX, scY, 12, cornerPaint);
|
||||
canvas.drawCircle(scR, scY, 12, cornerPaint);
|
||||
canvas.drawCircle(scX, scB, 12, cornerPaint);
|
||||
canvas.drawCircle(scR, scB, 12, cornerPaint);
|
||||
canvas.drawCircle(cropRect.left, cropRect.top, 12, cornerPaint);
|
||||
canvas.drawCircle(cropRect.right, cropRect.top, 12, cornerPaint);
|
||||
canvas.drawCircle(cropRect.left, cropRect.bottom, 12, cornerPaint);
|
||||
canvas.drawCircle(cropRect.right, cropRect.bottom, 12, cornerPaint);
|
||||
} else {
|
||||
canvas.drawRect(cropRect, borderPaint);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user