@react-native-ohos/react-native-image-crop-picker 0.40.4-rc.1
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/ COMMITTERS.md +9 -0
- package/.github/FUNDING.yml +1 -0
- package/CODE_OF_CONDUCT.md +0 -0
- package/CONTRIBUTING.md +68 -0
- package/ISSUE_TEMPLATE.md +34 -0
- package/LICENSE +21 -0
- package/OAT.xml +75 -0
- package/README.OpenSource +11 -0
- package/README.md +13 -0
- package/harmony/image_crop_picker/build-profile.json5 +8 -0
- package/harmony/image_crop_picker/hvigorfile.ts +1 -0
- package/harmony/image_crop_picker/index.ets +6 -0
- package/harmony/image_crop_picker/oh-package.json5 +10 -0
- package/harmony/image_crop_picker/src/main/cpp/CMakeLists.txt +9 -0
- package/harmony/image_crop_picker/src/main/cpp/ImageCropPickerPackage.h +19 -0
- package/harmony/image_crop_picker/src/main/cpp/generated/RNOH/generated/BaseReactNativeImageCropPickerPackage.h +66 -0
- package/harmony/image_crop_picker/src/main/cpp/generated/RNOH/generated/turbo_modules/ImageCropPicker.cpp +20 -0
- package/harmony/image_crop_picker/src/main/cpp/generated/RNOH/generated/turbo_modules/ImageCropPicker.h +16 -0
- package/harmony/image_crop_picker/src/main/ets/ImageCropPickerPackage.ts +28 -0
- package/harmony/image_crop_picker/src/main/ets/ImageCropPickerTurboModule.ts +1041 -0
- package/harmony/image_crop_picker/src/main/ets/Logger.ts +38 -0
- package/harmony/image_crop_picker/src/main/ets/generated/components/ts.ts +5 -0
- package/harmony/image_crop_picker/src/main/ets/generated/index.ets +5 -0
- package/harmony/image_crop_picker/src/main/ets/generated/ts.ts +6 -0
- package/harmony/image_crop_picker/src/main/ets/generated/turboModules/ImageCropPicker.ts +30 -0
- package/harmony/image_crop_picker/src/main/ets/generated/turboModules/ts.ts +5 -0
- package/harmony/image_crop_picker/src/main/ets/pages/ImageEditInfo.ets +862 -0
- package/harmony/image_crop_picker/src/main/ets/utils/Constants.ets +14 -0
- package/harmony/image_crop_picker/src/main/ets/utils/CropModel.ets +73 -0
- package/harmony/image_crop_picker/src/main/ets/utils/DecodeAndEncodeUtil.ets +54 -0
- package/harmony/image_crop_picker/src/main/ets/utils/EncodeUtil.ets +33 -0
- package/harmony/image_crop_picker/src/main/ets/utils/jul.ts +7 -0
- package/harmony/image_crop_picker/src/main/ets/utils/types.ets +94 -0
- package/harmony/image_crop_picker/src/main/ets/viewmodel/viewAndModel.ets +38 -0
- package/harmony/image_crop_picker/src/main/module.json5 +9 -0
- package/harmony/image_crop_picker/src/main/resources/base/element/string.json +20 -0
- package/harmony/image_crop_picker/src/main/resources/base/media/ic_anti_clockwise.png +0 -0
- package/harmony/image_crop_picker/src/main/resources/base/media/ic_clockwise.png +0 -0
- package/harmony/image_crop_picker/src/main/resources/base/media/ic_reset.png +0 -0
- package/harmony/image_crop_picker/src/main/resources/base/media/ic_save.png +0 -0
- package/harmony/image_crop_picker/src/main/resources/base/media/icon.png +0 -0
- package/harmony/image_crop_picker/src/main/resources/base/profile/main_pages.json +5 -0
- package/harmony/image_crop_picker/src/main/resources/en_US/element/string.json +8 -0
- package/harmony/image_crop_picker/src/main/resources/zh_CN/element/string.json +8 -0
- package/harmony/image_crop_picker/ts.ts +17 -0
- package/harmony/image_crop_picker.har +0 -0
- package/index.d.ts +512 -0
- package/js/NativeRNCImageCropPicker.ts +108 -0
- package/js/index.js +31 -0
- package/package.json +48 -0
- package/svg.svg +122 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
|
|
2
|
+
// Use of this source code is governed by a MIT license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
export class Constants {
|
|
6
|
+
static readonly ENCODE_FORMAT: string = 'image/jpeg';
|
|
7
|
+
static readonly ENCODE_QUALITY: number = 100;
|
|
8
|
+
static readonly DOUBLE_NUMBER: number = 2;
|
|
9
|
+
static readonly CLOCK_WISE: number = 90;
|
|
10
|
+
static readonly ANTI_CLOCK: number = -90;
|
|
11
|
+
static readonly IMAGE_FORMAT: string = '.jpg'
|
|
12
|
+
static readonly IMAGE_PREFIX: string = 'image';
|
|
13
|
+
static readonly ENCODE_FILE_PERMISSION: string = 'rw'
|
|
14
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
|
|
2
|
+
// Use of this source code is governed by a MIT license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
export class CropScaleClass {
|
|
6
|
+
value: number;
|
|
7
|
+
ratio: string;
|
|
8
|
+
cropIndex: number;
|
|
9
|
+
text: string | Resource;
|
|
10
|
+
key: string = '';
|
|
11
|
+
|
|
12
|
+
constructor(value: number, ratio: string, cropIndex: number, text: string | Resource, key?: string) {
|
|
13
|
+
this.value = value;
|
|
14
|
+
this.ratio = ratio;
|
|
15
|
+
this.cropIndex = cropIndex;
|
|
16
|
+
this.text = text;
|
|
17
|
+
key && (this.key = key);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class DownPos{
|
|
22
|
+
left: number
|
|
23
|
+
top: number
|
|
24
|
+
bottom: number
|
|
25
|
+
right: number
|
|
26
|
+
|
|
27
|
+
constructor(left: number, top: number, bottom: number, right: number) {
|
|
28
|
+
this.left = left;
|
|
29
|
+
this.top = top;
|
|
30
|
+
this.bottom = bottom;
|
|
31
|
+
this.right = right;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export class DragObj{
|
|
36
|
+
x: number
|
|
37
|
+
y: number
|
|
38
|
+
dragging: boolean
|
|
39
|
+
action: Action
|
|
40
|
+
downPos: DownPos
|
|
41
|
+
multiCrop: boolean
|
|
42
|
+
|
|
43
|
+
constructor(dragging: boolean, x: number = 0, y: number = 0,
|
|
44
|
+
action: Action = new Action(false, false, false, false),
|
|
45
|
+
downPos: DownPos = new DownPos(0, 0, 0, 0), multiCrop: boolean = false) {
|
|
46
|
+
this.dragging = dragging;
|
|
47
|
+
this.x = x;
|
|
48
|
+
this.y = y;
|
|
49
|
+
this.action = action;
|
|
50
|
+
this.downPos = downPos;
|
|
51
|
+
this.multiCrop = multiCrop;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export class Action {
|
|
56
|
+
left: boolean
|
|
57
|
+
top: boolean
|
|
58
|
+
right: boolean
|
|
59
|
+
bottom: boolean
|
|
60
|
+
|
|
61
|
+
constructor(left: boolean, top: boolean, right: boolean, bottom: boolean) {
|
|
62
|
+
this.left = left;
|
|
63
|
+
this.top = top;
|
|
64
|
+
this.right = right;
|
|
65
|
+
this.bottom = bottom;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export enum CropType {
|
|
70
|
+
FREE_CROP,
|
|
71
|
+
FIXED_RATIO,
|
|
72
|
+
FRAME_CROP
|
|
73
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
|
|
2
|
+
// Use of this source code is governed by a MIT license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
import fs from '@ohos.file.fs';
|
|
6
|
+
import image from '@ohos.multimedia.image';
|
|
7
|
+
import { Constants } from '../utils/Constants';
|
|
8
|
+
import { photoAccessHelper } from '@kit.MediaLibraryKit';
|
|
9
|
+
import { fileIo } from '@kit.CoreFileKit'
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
const TAG: string = 'imageCrop_Decode_Encode';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Async create pixel map.
|
|
16
|
+
*
|
|
17
|
+
* @return pixelMa.
|
|
18
|
+
*/
|
|
19
|
+
export async function getPixelMap(uri: string){
|
|
20
|
+
const file = fs.openSync(uri, fs.OpenMode.READ_ONLY);
|
|
21
|
+
const fd = file?.fd;
|
|
22
|
+
// path为已获得的沙箱路径
|
|
23
|
+
const imageSource = image.createImageSource(fd);
|
|
24
|
+
const pixelMap = await imageSource.createPixelMap({
|
|
25
|
+
editable: true
|
|
26
|
+
});
|
|
27
|
+
return pixelMap
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function encode(component: Object, pixelMap: PixelMap) {
|
|
31
|
+
const newPixelMap = pixelMap;
|
|
32
|
+
// Packing image.
|
|
33
|
+
const imagePackerApi = image.createImagePacker();
|
|
34
|
+
const packOptions: image.PackingOption = {
|
|
35
|
+
format: Constants.ENCODE_FORMAT,
|
|
36
|
+
quality: Constants.ENCODE_QUALITY
|
|
37
|
+
}
|
|
38
|
+
const imageData = await imagePackerApi.packing(newPixelMap, packOptions);
|
|
39
|
+
// Get album's path.
|
|
40
|
+
const context = getContext(component);
|
|
41
|
+
const media = photoAccessHelper.getPhotoAccessHelper(context);
|
|
42
|
+
const currentTime = new Date().getTime();
|
|
43
|
+
// Create image asset.
|
|
44
|
+
const filePath = await media.createAsset(
|
|
45
|
+
photoAccessHelper.PhotoType.IMAGE,
|
|
46
|
+
`${Constants.IMAGE_PREFIX}_${currentTime}${Constants.IMAGE_FORMAT}`,
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
let file = fileIo.openSync(filePath, fileIo.OpenMode.CREATE | fileIo.OpenMode.READ_WRITE)
|
|
50
|
+
await fs.write(file.fd, imageData);
|
|
51
|
+
// Image resource release.
|
|
52
|
+
imagePackerApi.release();
|
|
53
|
+
await media.release();
|
|
54
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
|
|
2
|
+
// Use of this source code is governed by a MIT license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
import fs from '@ohos.file.fs';
|
|
6
|
+
import image from '@ohos.multimedia.image';
|
|
7
|
+
import Logger from '../Logger';
|
|
8
|
+
import { Constants } from '../utils/Constants'
|
|
9
|
+
import util from '@ohos.util';
|
|
10
|
+
|
|
11
|
+
const TAG: string = 'imageEdit_Encode';
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
export async function encode(component: Object, pixelMap: ESObject) : Promise<string> {
|
|
15
|
+
let imgPath: string = '';
|
|
16
|
+
const newPixelMap: ESObject = pixelMap;
|
|
17
|
+
const imagePackerApi = image.createImagePacker();
|
|
18
|
+
const packOptions: image.PackingOption = {
|
|
19
|
+
format: Constants.ENCODE_FORMAT,
|
|
20
|
+
quality: Constants.ENCODE_QUALITY
|
|
21
|
+
}
|
|
22
|
+
let packerData = await imagePackerApi.packing(newPixelMap, packOptions);
|
|
23
|
+
Logger.info(TAG, 'into compressPictures data: ' + JSON.stringify(packerData));
|
|
24
|
+
const context = getContext(component);
|
|
25
|
+
imgPath = context.tempDir + '/rn_image_crop_picker_lib_temp_' + util.generateRandomUUID(true) + Constants.IMAGE_FORMAT;
|
|
26
|
+
let newFile = fs.openSync(imgPath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE);
|
|
27
|
+
Logger.info(TAG, 'into compressPictures newFile id: ' + newFile.fd);
|
|
28
|
+
const number = fs.writeSync(newFile.fd, packerData);
|
|
29
|
+
Logger.info(TAG, 'into compressPictures write data to file succeed size: ' + number);
|
|
30
|
+
fs.closeSync(newFile.fd);
|
|
31
|
+
imagePackerApi.release();
|
|
32
|
+
return imgPath;
|
|
33
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
|
|
2
|
+
// Use of this source code is governed by a MIT license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
@Observed
|
|
6
|
+
export class Rectangle {
|
|
7
|
+
left: number;
|
|
8
|
+
top: number;
|
|
9
|
+
right: number;
|
|
10
|
+
bottom: number;
|
|
11
|
+
|
|
12
|
+
constructor(left: number, top: number, right: number, bottom: number){
|
|
13
|
+
this.left = left;
|
|
14
|
+
this.top = top;
|
|
15
|
+
this.right = right;
|
|
16
|
+
this.bottom = bottom;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
width(): number {
|
|
20
|
+
return this.right - this.left;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
height(): number {
|
|
24
|
+
return this.bottom - this.top;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
centerX(): number {
|
|
28
|
+
return this.left + this.width() / 2;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
centerY(): number {
|
|
32
|
+
return this.top + this.height() / 2;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
roundLeft(): number {
|
|
36
|
+
return Math.floor(vp2px(this.left));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
roundRight(): number {
|
|
40
|
+
return Math.floor(vp2px(this.right));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
roundTop(): number {
|
|
44
|
+
return Math.floor(vp2px(this.top));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
roundBottom(): number {
|
|
48
|
+
return Math.floor(vp2px(this.bottom));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
roundWidth(): number {
|
|
52
|
+
return this.roundRight() - this.roundLeft();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
roundHeight(): number {
|
|
56
|
+
return this.roundBottom() - this.roundTop();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
scale(ratio: number, originPointX: number, originPointY: number): Rectangle {
|
|
60
|
+
let left = originPointX + (this.left - originPointX) * ratio;
|
|
61
|
+
let top = originPointY + (this.top - originPointY) * ratio;
|
|
62
|
+
let right = originPointX + (this.right - originPointX) * ratio;
|
|
63
|
+
let bottom = originPointY + (this.bottom - originPointY) * ratio;
|
|
64
|
+
return new Rectangle (left, top, right, bottom);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
translate(offsetX: number, offsetY: number): Rectangle {
|
|
68
|
+
let left = this.left + offsetX;
|
|
69
|
+
let top = this.top + offsetY;
|
|
70
|
+
let right = this.right + offsetX;
|
|
71
|
+
let bottom = this.bottom + offsetY;
|
|
72
|
+
return new Rectangle (left, top, right, bottom);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
clone(): Rectangle {
|
|
76
|
+
return new Rectangle(this.left, this.top, this.right, this.bottom);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
toString() {
|
|
80
|
+
return 'Rect[' + this.left + ',' + this.top + ',' + this.right + ',' + this.bottom + ']';
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@Observed
|
|
85
|
+
export class TextDrawStatus {
|
|
86
|
+
public currentTab: string = 'text';
|
|
87
|
+
public play_pos: number = 0;
|
|
88
|
+
public fixWidth: number = 0;
|
|
89
|
+
public fixHeight: number = 0;
|
|
90
|
+
public currentTextUid: string = '';
|
|
91
|
+
public trimerMove: boolean = false;
|
|
92
|
+
public identifyStatus: number = -1
|
|
93
|
+
public identifyResult: number = -1
|
|
94
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
|
|
2
|
+
// Use of this source code is governed by a MIT license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
export class RegionItem {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
constructor(x: number, y: number) {
|
|
9
|
+
this.x = x;
|
|
10
|
+
this.y = y;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class IconStatus {
|
|
15
|
+
normal: Resource;
|
|
16
|
+
chosen: Resource;
|
|
17
|
+
constructor(normal: Resource, chosen: Resource) {
|
|
18
|
+
this.normal = normal;
|
|
19
|
+
this.chosen = chosen;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export enum CropType {
|
|
24
|
+
ORIGINAL_IMAGE,
|
|
25
|
+
SQUARE,
|
|
26
|
+
BANNER,
|
|
27
|
+
RECTANGLE
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export enum RotateType {
|
|
31
|
+
CLOCKWISE,
|
|
32
|
+
ANTI_CLOCK
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export enum MainTabId {
|
|
36
|
+
CROP,
|
|
37
|
+
ROTATE
|
|
38
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"string": [
|
|
3
|
+
{
|
|
4
|
+
"name": "module_desc",
|
|
5
|
+
"value": "module description"
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
"name": "EntryAbility_desc",
|
|
9
|
+
"value": "description"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"name": "EntryAbility_label",
|
|
13
|
+
"value": "ImageEdit"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"name": "reason",
|
|
17
|
+
"value": "save image"
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export * from "./src/main/ets/ImageCropPickerPackage";
|
|
17
|
+
export * from "./src/main/ets/ImageCropPickerTurboModule";
|
|
Binary file
|