!607 图库中图片按照角度旋转时,图片自动放大

Merge pull request !607 from ywz/OpenHarmony-4.1-Release
This commit is contained in:
openharmony_ci 2024-09-24 09:46:16 +00:00 committed by Gitee
commit 8c7d9cd1d9
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 30 additions and 1 deletions

View File

@ -105,8 +105,25 @@ export class CropShow {
let points = MathUtils.rectToPoints(this.cropRect);
let origin = this.getDisplayCenter();
let totalAngle = -(this.rotationAngle + this.horizontalAngle);
let isLeft: boolean = true;
let rotationIndex = Constants.NUMBER_0;
const rotationAngleAbs = Math.abs(this.rotationAngle);
if (rotationAngleAbs === Constants.NUMBER_0) {
rotationIndex = angle > Constants.NUMBER_0 ? Constants.NUMBER_0 : Constants.NUMBER_1;
isLeft = angle > Constants.NUMBER_0;
} else if (rotationAngleAbs === Constants.ANGLE_90) {
rotationIndex = angle < Constants.NUMBER_0 ? Constants.NUMBER_0 : Constants.NUMBER_1;
isLeft = angle < Constants.NUMBER_0;
} else if (rotationAngleAbs === Constants.ANGLE_180) {
rotationIndex = angle > Constants.NUMBER_0 ? Constants.NUMBER_0 : Constants.NUMBER_1;
isLeft = angle < Constants.NUMBER_0;
} else if (rotationAngleAbs === Constants.ANGLE_270) {
rotationIndex = angle < Constants.NUMBER_0 ? Constants.NUMBER_0 : Constants.NUMBER_1;
isLeft = angle > Constants.NUMBER_0;
}
let rotated = MathUtils.rotatePoints(points, totalAngle, origin);
let scale = MathUtils.findSuitableScale(rotated, this.imageRect, origin);
let curRotated = rotated[rotationIndex];
let scale = MathUtils.findRotationAngleScale(curRotated, this.imageRect, origin, isLeft);
MathUtils.scaleRectBasedOnPoint(this.imageRect, origin, scale);
}
@ -175,6 +192,7 @@ export class CropShow {
// Recalculate crop Rect.
MathUtils.computeMaxRectWithinLimit(newCrop, this.limitRect, cropRatio);
let scale: number = newCrop.getWidth() / this.cropRect.getWidth();
Log.info(TAG, `enlargeCropArea scale: ${scale}`);
// Scale Image based on the midpoint of the last crop.
let tX: number = this.isFlipHorizontal ? -1 : 1;

View File

@ -168,6 +168,17 @@ export abstract class MathUtils {
return scale;
}
static findRotationAngleScale(points: Point, rect: RectF, origin: Point,isLeft: boolean): number {
let scale = 1;
if (isLeft) {
scale = (points.x - origin.x) / (rect.left - origin.x)
}else {
scale = (points.x - origin.x) / (rect.right - origin.x)
}
return Math.abs(scale);
}
static fixImageMove(rotated: Array<Point>, flipImage: RectF): Array<number> {
let offsetX = 0;
let offsetY = 0;