@react-native-ohos/react-native-image-crop-picker 0.40.5-rc.2 → 0.40.5-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -129,7 +129,6 @@ export struct ImageEditInfo {
|
|
|
129
129
|
private minSize = PHONE_MIN_CROP // 最小宽高
|
|
130
130
|
private dragObj: DragObj = new DragObj(false);
|
|
131
131
|
private clb: number = 1
|
|
132
|
-
private canClip: boolean = true
|
|
133
132
|
|
|
134
133
|
pixelInit(path: string) {
|
|
135
134
|
this.angle = 0;
|
|
@@ -173,16 +172,14 @@ export struct ImageEditInfo {
|
|
|
173
172
|
|
|
174
173
|
this.maxClipSize = new Rectangle(left, top, right, bottom);
|
|
175
174
|
|
|
176
|
-
if (this.initWidth > 0) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
if(!!this.initWidth && !!this.initHeight){
|
|
185
|
-
this.canClip = false
|
|
175
|
+
if (this.initWidth > 0 && this.initHeight > 0) {
|
|
176
|
+
let flag = imageWidth/this.initWidth < imageHeight/this.initHeight;
|
|
177
|
+
let _imgWidth = flag ? imgWidth : Math.round(imgHeight * this.initWidth / this.initHeight)
|
|
178
|
+
let _imgHeight = !flag ? imgHeight : Math.round(imgWidth * this.initHeight / this.initWidth)
|
|
179
|
+
left = (screenWidth - _imgWidth) / 2;
|
|
180
|
+
right = _imgWidth + left;
|
|
181
|
+
top = (screenHeight - _imgHeight) / 2 - 66;
|
|
182
|
+
bottom = _imgHeight + top;
|
|
186
183
|
}
|
|
187
184
|
|
|
188
185
|
this.clipSize = new Rectangle(left, top, right, bottom);
|
|
@@ -367,17 +364,20 @@ export struct ImageEditInfo {
|
|
|
367
364
|
let region: image.Region = { x: 0, y: 0, size: { height: cropHeight, width: cropWidth } };
|
|
368
365
|
region.x =
|
|
369
366
|
(this.clipSize.left - this.maxClipSize.left) / this.imgScale * this.clb + (xOff / this.imgScale) - this.imgOffSetX / this.imgScale * this.clb;
|
|
370
|
-
region.size.width = cropWidth - region.x - (this.maxClipSize.right - this.clipSize.right) / this.imgScale * this.clb
|
|
371
|
-
- (xOff / this.imgScale) - this.imgOffSetX / this.imgScale * this.clb;
|
|
367
|
+
region.size.width = Math.round(cropWidth - region.x - (this.maxClipSize.right - this.clipSize.right) / this.imgScale * this.clb
|
|
368
|
+
- (xOff / this.imgScale) - this.imgOffSetX / this.imgScale * this.clb);
|
|
372
369
|
region.y =
|
|
373
370
|
(this.clipSize.top - this.maxClipSize.top) / this.imgScale * this.clb + (yOff / this.imgScale) - this.imgOffSetY / this.imgScale * this.clb;
|
|
374
|
-
region.size.height = cropHeight - region.y - (this.maxClipSize.bottom - this.clipSize.bottom) / this.imgScale * this.clb
|
|
375
|
-
- (yOff / this.imgScale) - this.imgOffSetY / this.imgScale * this.clb;
|
|
371
|
+
region.size.height = Math.round(cropHeight - region.y - (this.maxClipSize.bottom - this.clipSize.bottom) / this.imgScale * this.clb
|
|
372
|
+
- (yOff / this.imgScale) - this.imgOffSetY / this.imgScale * this.clb);
|
|
376
373
|
this.icon.crop(region, async (err: BusinessError) => {
|
|
377
374
|
if (err != undefined) {
|
|
378
375
|
console.error("Failed to crop pixelmap.");
|
|
379
376
|
return;
|
|
380
377
|
} else {
|
|
378
|
+
if (this.initWidth > 0 && this.initHeight > 0){
|
|
379
|
+
this.icon?.scaleSync( this.initWidth / region.size.width, this.initHeight / region.size.height )
|
|
380
|
+
}
|
|
381
381
|
let imgPath = await encode(this, this.icon);
|
|
382
382
|
AppStorage.setOrCreate('cropImagePath', imgPath)
|
|
383
383
|
AppStorage.setOrCreate('cropRect', {
|
|
@@ -552,7 +552,7 @@ export struct ImageEditInfo {
|
|
|
552
552
|
return;
|
|
553
553
|
}
|
|
554
554
|
this.imageFlag = false;
|
|
555
|
-
if (this.freeStyleCropEnabled) {
|
|
555
|
+
if (!this.freeStyleCropEnabled) {
|
|
556
556
|
return;
|
|
557
557
|
}
|
|
558
558
|
let touch = event.touches[0];
|
|
@@ -563,8 +563,6 @@ export struct ImageEditInfo {
|
|
|
563
563
|
let newPosition = this.clipSize.clone();
|
|
564
564
|
|
|
565
565
|
let direction = this.dragObj.action;
|
|
566
|
-
|
|
567
|
-
if(!this.canClip) return;
|
|
568
566
|
|
|
569
567
|
if (this.dragObj.multiCrop) {
|
|
570
568
|
this.getMultiCropRect(delX, delY, newPosition, direction, event.pressure);
|
|
Binary file
|