@react-native-ohos/react-native-image-crop-picker 0.51.2-rc.4 → 0.51.2-rc.6

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  ## 鸿蒙化Log
4
4
 
5
+ ### v0.51.2-rc.6
6
+
7
+ - fix: Adjust the saved format after image cropping and compression
8
+ - pre-release: @react-native-ohos/react-native-image-crop-picker@0.51.2-rc.6
9
+
10
+ ### v0.51.2-rc.5
11
+
12
+ - fix: Add the "freeStyleCropEnabled" attribute
13
+ - pre-release: @react-native-ohos/react-native-image-crop-picker@0.51.2-rc.5
14
+
5
15
  ### v0.51.2-rc.4
6
16
 
7
17
  - Fix: Support for multiple image formats in image compression. Fixed issues with openPicker and openCamera where circular cropping of images did not display properly.
@@ -3,7 +3,7 @@
3
3
  "description": "Please describe the basic information.",
4
4
  "main": "index.ets",
5
5
  "type": "module",
6
- "version": "0.51.2-rc.4",
6
+ "version": "0.51.2-rc.6",
7
7
  "dependencies": {
8
8
  "@rnoh/react-native-openharmony": "file:../../node_modules/@react-native-oh/react-native-harmony/harmony/react_native_openharmony.har"
9
9
  },
@@ -698,40 +698,17 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
698
698
  let imageISs = image.createImageSource(files.fd);
699
699
  let imagePMs = await imageISs.createPixelMap();
700
700
  let imagePackerApi = await image.createImagePacker();
701
- let jpgToJpeg = (imageType == 'jpg' ? 'jpeg' : imageType);
702
- if (imageType == 'bmp') {
703
- jpgToJpeg = 'jpeg';
704
- }
705
701
  let dstPath =
706
702
  this.ctx.uiAbilityContext.tempDir + '/rn_image_crop_picker_lib_temp_' + util.generateRandomUUID(true) +
707
703
  '.' + imageType;
708
- if (imageType == 'gif') {
709
- let pixelMapList = await imageISs.createPixelMapList();
710
- let options: image.PackingOption = {
711
- format: `image/jpeg`,
712
- quality: quality,
713
- };
714
- let packer = image.createImagePacker();
715
- let newFile = fs.openSync(dstPath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
716
- // 只取第一帧压缩 同时将图片转为jpeg来处理压缩
717
- let packerData = await packer.packToData(pixelMapList[0], options);
718
- const number = fs.writeSync(newFile.fd, packerData);
719
- fs.closeSync(newFile);
720
- } else {
721
- if(imageType == 'sdr_astc_4x4' || imageType == 'sdr_sut_superfast_4x4'){
722
- quality = 92;
723
- } else if(imageType == 'hdr_astc_4x4'){
724
- quality = 85;
725
- }
726
- let options: image.PackingOption = {
727
- format: `image/${jpgToJpeg}`,
728
- quality: quality,
729
- };
730
- let newFile = fs.openSync(dstPath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
731
- let packerData = await imagePackerApi.packToData(imagePMs, options);
732
- const number = fs.writeSync(newFile.fd, packerData);
733
- fs.closeSync(newFile);
734
- }
704
+ let options: image.PackingOption = {
705
+ format: `image/jpeg`,
706
+ quality: quality,
707
+ };
708
+ let newFile = fs.openSync(dstPath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
709
+ let packerData = await imagePackerApi.packToData(imagePMs, options);
710
+ const number = fs.writeSync(newFile.fd, packerData);
711
+ fs.closeSync(newFile);
735
712
  resultImages.push(dstPath);
736
713
  fs.closeSync(files);
737
714
  } else {
@@ -1252,7 +1252,9 @@ export struct ImageEditInfo {
1252
1252
  return;
1253
1253
  }
1254
1254
  this.imageFlag = false;
1255
-
1255
+ if (!this.freeStyleCropEnabled) {
1256
+ return;
1257
+ }
1256
1258
  let touch = event.touches[0];
1257
1259
  let delX: number = touch.screenX - this.dragObj.x;
1258
1260
  let delY: number = touch.screenY - this.dragObj.y;
@@ -30,50 +30,22 @@ import util from '@ohos.util';
30
30
 
31
31
  const TAG: string = 'imageEdit_Encode';
32
32
 
33
-
34
33
  export async function encode(component: Object, pixelMap: ESObject) : Promise<string> {
34
+ let imgPath: string = '';
35
35
  const newPixelMap: ESObject = pixelMap;
36
36
  const imagePackerApi = image.createImagePacker();
37
- let imagePath = AppStorage.get('filePath') as string;
38
-
39
- let i = imagePath.lastIndexOf('.');
40
- let imageType = 'jpg';
41
- if (i != -1) {
42
- imageType = imagePath.substring(i + 1);
43
- }
44
- let jpgToJpeg = (imageType == 'jpg' ? 'jpeg' : imageType);
45
- if (imageType == 'bmp') {
46
- jpgToJpeg = 'jpeg';
37
+ const packOptions: image.PackingOption = {
38
+ format: Constants.ENCODE_FORMAT,
39
+ quality: Constants.ENCODE_QUALITY
47
40
  }
41
+ let packerData = await imagePackerApi.packing(newPixelMap, packOptions);
48
42
  const context = getContext(component);
49
- let dstPath = context.tempDir + '/rn_image_crop_picker_lib_temp_' + util.generateRandomUUID(true) + '.' + imageType;
50
- if (imageType == 'gif') {
51
- let options: image.PackingOption = {
52
- format: `image/jpeg`,
53
- quality: 100,
54
- };
55
- let newFile = fs.openSync(dstPath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
56
- let packerData = await imagePackerApi.packToData(newPixelMap, options);
57
- const number = fs.writeSync(newFile.fd, packerData);
58
- fs.closeSync(newFile);
59
- } else {
60
- let quality = Constants.ENCODE_QUALITY;
61
- if(imageType == 'sdr_astc_4x4' || imageType == 'sdr_sut_superfast_4x4'){
62
- quality = 92;
63
- } else if(imageType == 'hdr_astc_4x4'){
64
- quality = 85;
65
- }
66
- let options: image.PackingOption = {
67
- format: `image/${jpgToJpeg}`,
68
- quality: quality,
69
- };
70
- let newFile = fs.openSync(dstPath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
71
- let packerData = await imagePackerApi.packToData(newPixelMap, options);
72
- const number = fs.writeSync(newFile.fd, packerData);
73
- fs.closeSync(newFile);
74
- }
43
+ imgPath = context.tempDir + '/rn_image_crop_picker_lib_temp_' + util.generateRandomUUID(true) + Constants.IMAGE_FORMAT;
44
+ let newFile = fs.openSync(imgPath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
45
+ const number = fs.writeSync(newFile.fd, packerData);
46
+ fs.closeSync(newFile.fd);
75
47
  imagePackerApi.release();
76
- return dstPath;
48
+ return imgPath;
77
49
  }
78
50
 
79
51
  // PNG编码函数
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.51.2-rc.4",
3
+ "version": "0.51.2-rc.6",
4
4
  "description": "Select single or multiple images, with cropping option",
5
5
  "main": "js/index.js",
6
6
  "scripts": {