@react-native-ohos/react-native-image-crop-picker 0.40.5-rc.8 → 0.40.5

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
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ### v0.40.5-rc.11
4
+
5
+ - pre-release: @react-native-ohos/react-native-image-crop-picker@0.40.5-rc.11
6
+
7
+ ### v0.40.5-rc.10
8
+
9
+ - fix: Adjust the saved format after image cropping and compression
10
+ - pre-release: @react-native-ohos/react-native-image-crop-picker@0.40.5-rc.10
11
+
12
+ ### v0.40.5-rc.9
13
+
14
+ - fix: Add the "freeStyleCropEnabled" attribute
15
+ - pre-release: @react-native-ohos/react-native-image-crop-picker@0.40.5-rc.9
16
+
3
17
  ## v0.40.5-rc.1
4
18
  - Fix the issue where the file size after compression is larger than the original file.
5
19
 
@@ -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.8',
6
+ version: '0.40.5',
7
7
  dependencies: {
8
8
  "@rnoh/react-native-openharmony": "^0.72.38"
9
9
  },
@@ -675,40 +675,17 @@ export class ImageCropPickerTurboModule extends TurboModule implements ImageCrop
675
675
  let imageISs = image.createImageSource(files.fd);
676
676
  let imagePMs = await imageISs.createPixelMap();
677
677
  let imagePackerApi = await image.createImagePacker();
678
- let jpgToJpeg = (imageType == 'jpg' ? 'jpeg' : imageType);
679
- if (imageType == 'bmp') {
680
- jpgToJpeg = 'jpeg';
681
- }
682
678
  let dstPath =
683
679
  this.ctx.uiAbilityContext.tempDir + '/rn_image_crop_picker_lib_temp_' + util.generateRandomUUID(true) +
684
680
  '.' + imageType;
685
- if (imageType == 'gif') {
686
- let pixelMapList = await imageISs.createPixelMapList();
687
- let options: image.PackingOption = {
688
- format: `image/jpeg`,
689
- quality: quality,
690
- };
691
- let packer = image.createImagePacker();
692
- let newFile = fs.openSync(dstPath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
693
- // 只取第一帧压缩(保持与IOS一致) 同时将图片转为jpeg来处理压缩
694
- let packerData = await packer.packToData(pixelMapList[0], options);
695
- const number = fs.writeSync(newFile.fd, packerData);
696
- fs.closeSync(newFile);
697
- } else {
698
- if(imageType == 'sdr_astc_4x4' || imageType == 'sdr_sut_superfast_4x4'){
699
- quality = 92;
700
- } else if(imageType == 'hdr_astc_4x4'){
701
- quality = 85;
702
- }
703
- let options: image.PackingOption = {
704
- format: `image/${jpgToJpeg}`,
705
- quality: quality,
706
- };
707
- let newFile = fs.openSync(dstPath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
708
- let packerData = await imagePackerApi.packToData(imagePMs, options);
709
- const number = fs.writeSync(newFile.fd, packerData);
710
- fs.closeSync(newFile);
711
- }
681
+ let options: image.PackingOption = {
682
+ format: `image/jpeg`,
683
+ quality: quality,
684
+ };
685
+ let newFile = fs.openSync(dstPath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
686
+ let packerData = await imagePackerApi.packToData(imagePMs, options);
687
+ const number = fs.writeSync(newFile.fd, packerData);
688
+ fs.closeSync(newFile);
712
689
  resultImages.push(dstPath);
713
690
  fs.closeSync(files);
714
691
  } else {
@@ -1234,7 +1234,9 @@ export struct ImageEditInfo {
1234
1234
  return;
1235
1235
  }
1236
1236
  this.imageFlag = false;
1237
-
1237
+ if (!this.freeStyleCropEnabled) {
1238
+ return;
1239
+ }
1238
1240
  let touch = event.touches[0];
1239
1241
  let delX: number = touch.screenX - this.dragObj.x;
1240
1242
  let delY: number = touch.screenY - this.dragObj.y;
@@ -11,48 +11,21 @@ import util from '@ohos.util';
11
11
  const TAG: string = 'imageEdit_Encode';
12
12
 
13
13
  export async function encode(component: Object, pixelMap: ESObject) : Promise<string> {
14
+ let imgPath: string = '';
14
15
  const newPixelMap: ESObject = pixelMap;
15
16
  const imagePackerApi = image.createImagePacker();
16
- let imagePath = AppStorage.get('filePath') as string;
17
-
18
- let i = imagePath.lastIndexOf('.');
19
- let imageType = 'jpg';
20
- if (i != -1) {
21
- imageType = imagePath.substring(i + 1);
22
- }
23
- let jpgToJpeg = (imageType == 'jpg' ? 'jpeg' : imageType);
24
- if (imageType == 'bmp') {
25
- jpgToJpeg = 'jpeg';
17
+ const packOptions: image.PackingOption = {
18
+ format: Constants.ENCODE_FORMAT,
19
+ quality: Constants.ENCODE_QUALITY
26
20
  }
21
+ let packerData = await imagePackerApi.packing(newPixelMap, packOptions);
27
22
  const context = getContext(component);
28
- let dstPath = context.tempDir + '/rn_image_crop_picker_lib_temp_' + util.generateRandomUUID(true) + '.' + imageType;
29
- if (imageType == 'gif') {
30
- let options: image.PackingOption = {
31
- format: `image/jpeg`,
32
- quality: 100,
33
- };
34
- let newFile = fs.openSync(dstPath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
35
- let packerData = await imagePackerApi.packToData(newPixelMap, options);
36
- const number = fs.writeSync(newFile.fd, packerData);
37
- fs.closeSync(newFile);
38
- } else {
39
- let quality = Constants.ENCODE_QUALITY;
40
- if(imageType == 'sdr_astc_4x4' || imageType == 'sdr_sut_superfast_4x4'){
41
- quality = 92;
42
- } else if(imageType == 'hdr_astc_4x4'){
43
- quality = 85;
44
- }
45
- let options: image.PackingOption = {
46
- format: `image/${jpgToJpeg}`,
47
- quality: quality,
48
- };
49
- let newFile = fs.openSync(dstPath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
50
- let packerData = await imagePackerApi.packToData(newPixelMap, options);
51
- const number = fs.writeSync(newFile.fd, packerData);
52
- fs.closeSync(newFile);
53
- }
23
+ imgPath = context.tempDir + '/rn_image_crop_picker_lib_temp_' + util.generateRandomUUID(true) + Constants.IMAGE_FORMAT;
24
+ let newFile = fs.openSync(imgPath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
25
+ const number = fs.writeSync(newFile.fd, packerData);
26
+ fs.closeSync(newFile.fd);
54
27
  imagePackerApi.release();
55
- return dstPath;
28
+ return imgPath;
56
29
  }
57
30
 
58
31
  // 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.40.5-rc.8",
3
+ "version": "0.40.5",
4
4
  "description": "Select single or multiple images, with cropping option",
5
5
  "main": "js/index.js",
6
6
  "scripts": {