@react-native-ohos/react-native-image-crop-picker 0.40.5-rc.1 → 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.
@@ -3,7 +3,7 @@
3
3
  "description": "Please describe the basic information.",
4
4
  main: 'index.ets',
5
5
  type: 'module',
6
- version: '0.40.5-rc.1',
6
+ version: '0.40.5-rc.3',
7
7
  dependencies: {
8
8
  "@rnoh/react-native-openharmony": "^0.72.38"
9
9
  },
@@ -172,13 +172,14 @@ export struct ImageEditInfo {
172
172
 
173
173
  this.maxClipSize = new Rectangle(left, top, right, bottom);
174
174
 
175
- if (this.initWidth > 0) {
176
- left = (screenWidth - this.initWidth) / 2;
177
- right = this.initWidth + left;
178
- }
179
- if (this.initHeight > 0) {
180
- top = (screenHeight - this.initHeight) / 2 - 66;
181
- bottom = this.initHeight + top;
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;
182
183
  }
183
184
 
184
185
  this.clipSize = new Rectangle(left, top, right, bottom);
@@ -363,17 +364,20 @@ export struct ImageEditInfo {
363
364
  let region: image.Region = { x: 0, y: 0, size: { height: cropHeight, width: cropWidth } };
364
365
  region.x =
365
366
  (this.clipSize.left - this.maxClipSize.left) / this.imgScale * this.clb + (xOff / this.imgScale) - this.imgOffSetX / this.imgScale * this.clb;
366
- region.size.width = cropWidth - region.x - (this.maxClipSize.right - this.clipSize.right) / this.imgScale * this.clb
367
- - (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);
368
369
  region.y =
369
370
  (this.clipSize.top - this.maxClipSize.top) / this.imgScale * this.clb + (yOff / this.imgScale) - this.imgOffSetY / this.imgScale * this.clb;
370
- region.size.height = cropHeight - region.y - (this.maxClipSize.bottom - this.clipSize.bottom) / this.imgScale * this.clb
371
- - (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);
372
373
  this.icon.crop(region, async (err: BusinessError) => {
373
374
  if (err != undefined) {
374
375
  console.error("Failed to crop pixelmap.");
375
376
  return;
376
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
+ }
377
381
  let imgPath = await encode(this, this.icon);
378
382
  AppStorage.setOrCreate('cropImagePath', imgPath)
379
383
  AppStorage.setOrCreate('cropRect', {
@@ -548,7 +552,7 @@ export struct ImageEditInfo {
548
552
  return;
549
553
  }
550
554
  this.imageFlag = false;
551
- if (this.freeStyleCropEnabled) {
555
+ if (!this.freeStyleCropEnabled) {
552
556
  return;
553
557
  }
554
558
  let touch = event.touches[0];
@@ -559,6 +563,7 @@ export struct ImageEditInfo {
559
563
  let newPosition = this.clipSize.clone();
560
564
 
561
565
  let direction = this.dragObj.action;
566
+
562
567
  if (this.dragObj.multiCrop) {
563
568
  this.getMultiCropRect(delX, delY, newPosition, direction, event.pressure);
564
569
  } else {
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-ohos/react-native-image-crop-picker",
3
- "version": "0.40.5-rc.1",
3
+ "version": "0.40.5-rc.3",
4
4
  "description": "Select single or multiple images, with cropping option",
5
5
  "main": "js/index.js",
6
6
  "scripts": {