diff --git a/ImageKit/AppScope/app.json5 b/ImageKit/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..011f7775a219ab9718cd92f567806bc9304d62cf --- /dev/null +++ b/ImageKit/AppScope/app.json5 @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "com.example.imagekit", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/ImageKit/AppScope/resources/base/element/string.json b/ImageKit/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..234d8a0af60826869deb035bfe30047a3d63bffe --- /dev/null +++ b/ImageKit/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ImageKit" + } + ] +} diff --git a/ImageKit/AppScope/resources/base/media/background.png b/ImageKit/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/ImageKit/AppScope/resources/base/media/background.png differ diff --git a/ImageKit/AppScope/resources/base/media/foreground.png b/ImageKit/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/ImageKit/AppScope/resources/base/media/foreground.png differ diff --git a/ImageKit/AppScope/resources/base/media/layered_image.json b/ImageKit/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ImageKit/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ImageKit/build-profile.json5 b/ImageKit/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..03ac3a3ae9dd397844173066e5d5ee21b49455a1 --- /dev/null +++ b/ImageKit/build-profile.json5 @@ -0,0 +1,41 @@ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.4(16)", + "runtimeOS": "HarmonyOS", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/ImageKit/code-linter.json5 b/ImageKit/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..073990fa45394e1f8e85d85418ee60a8953f9b99 --- /dev/null +++ b/ImageKit/code-linter.json5 @@ -0,0 +1,32 @@ +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + "@security/no-unsafe-aes": "error", + "@security/no-unsafe-hash": "error", + "@security/no-unsafe-mac": "warn", + "@security/no-unsafe-dh": "error", + "@security/no-unsafe-dsa": "error", + "@security/no-unsafe-ecdsa": "error", + "@security/no-unsafe-rsa-encrypt": "error", + "@security/no-unsafe-rsa-sign": "error", + "@security/no-unsafe-rsa-key": "error", + "@security/no-unsafe-dsa-key": "error", + "@security/no-unsafe-dh-key": "error", + "@security/no-unsafe-3des": "error" + } +} \ No newline at end of file diff --git a/ImageKit/entry/build-profile.json5 b/ImageKit/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4d611879c7913fb0610c686e2399258ab3a6dad1 --- /dev/null +++ b/ImageKit/entry/build-profile.json5 @@ -0,0 +1,28 @@ +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ImageKit/entry/hvigorfile.ts b/ImageKit/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..c6edcd90486dd5a853cf7d34c8647f08414ca7a3 --- /dev/null +++ b/ImageKit/entry/hvigorfile.ts @@ -0,0 +1,6 @@ +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ImageKit/entry/obfuscation-rules.txt b/ImageKit/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/ImageKit/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/ImageKit/entry/oh-package.json5 b/ImageKit/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..248c3b7541a589682a250f86a6d3ecf7414d2d6a --- /dev/null +++ b/ImageKit/entry/oh-package.json5 @@ -0,0 +1,10 @@ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/ImageKit/entry/src/main/ets/entryability/EntryAbility.ets b/ImageKit/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..508880af8c33aa838016d1cd4b2c68be2f447540 --- /dev/null +++ b/ImageKit/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,44 @@ +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/ImageKit/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/ImageKit/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..8e4de99282050bad799ac892eb85ac5449364a51 --- /dev/null +++ b/ImageKit/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,16 @@ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/ImageKit/entry/src/main/ets/pages/ConvertPixelMapToCvMatFormat.ets b/ImageKit/entry/src/main/ets/pages/ConvertPixelMapToCvMatFormat.ets new file mode 100644 index 0000000000000000000000000000000000000000..a4b0b4b6803b9a7a747167d84b0bc3e169450d5d --- /dev/null +++ b/ImageKit/entry/src/main/ets/pages/ConvertPixelMapToCvMatFormat.ets @@ -0,0 +1,205 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:如何将C++侧接收的PixelMap转换成cv::mat格式 + */ + +// DocsCode 1 +import cPixelMapToMat from 'libcpixelmaptomat.so'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { image } from '@kit.ImageKit'; + +@Entry +@Component +struct Index { + @State pixelMap: image.PixelMap | undefined = undefined + + async arrayBufferToMat() { + if (this.pixelMap == undefined || this.pixelMap){ + let resourceManager = this.getUIContext().getHostContext()!.resourceManager + let imageArray = await resourceManager.getMediaContent($r('app.media.sample10')); + let pixelBuffer = new Uint8Array(imageArray).buffer as Object as ArrayBuffer + console.info("pixelBuffer length: " + pixelBuffer.byteLength); + let imageResource = image.createImageSource(pixelBuffer); + let opts: image.DecodingOptions = { + editable: true, + desiredPixelFormat: image.PixelMapFormat.RGBA_8888 + } + this.pixelMap = await imageResource.createPixelMap(opts); + } + + const readBuffer: ArrayBuffer = new ArrayBuffer(this.pixelMap.getPixelBytesNumber()); // 获取pixelmap的arraybuffer + console.info("readBuffer length: " + readBuffer.byteLength); + this.pixelMap.readPixelsToBuffer(readBuffer).then(() => { + console.info("No Error!") + }).catch((err: BusinessError) => { + console.error("Error! " + err.message) + }) + const dir = this.getUIContext().getHostContext()!.filesDir; + console.info('save path: ' + dir); + cPixelMapToMat.arrayBufferToMat(this.pixelMap, readBuffer, dir); + } + + async accessToMat(){ + if (this.pixelMap == undefined || this.pixelMap) { + let resourceManager = this.getUIContext().getHostContext()!.resourceManager + let imageArray = await resourceManager.getMediaContent($r('app.media.sample14')); + let pixelBuffer = new Uint8Array(imageArray).buffer as Object as ArrayBuffer + console.info("pixelBuffer length: " + pixelBuffer.byteLength); + let imageResource = image.createImageSource(pixelBuffer); + let opts: image.DecodingOptions = { + editable: true, + desiredPixelFormat: image.PixelMapFormat.RGBA_8888 + } + this.pixelMap = await imageResource.createPixelMap(opts); + } + + const dir = this.getUIContext().getHostContext()!.filesDir; + console.info('save path: ' + dir); + cPixelMapToMat.accessToMat(this.pixelMap, dir); + } + + build() { + Row() { + Column() { + Image(this.pixelMap) + .width(200) + .height(200) + Button('ArrayBufferToMat') + .onClick(() => { + this.arrayBufferToMat(); + }) + + Button('AccessToMat') + .onClick(() => { + this.accessToMat(); + }) + } + .width('100%') + } + .height('100%') + } +} +// DocsCode 1 + +// DocsCode 2 +#include "napi/native_api.h" +#include +#include +#include +#include +#include "hilog/log.h" +#include +#include + + static napi_value ArrayBufferToMat(napi_env env, napi_callback_info info) { + size_t argc = 3; + napi_value args[3] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + napi_value error; + napi_create_int32(env, -1, &error); + // 初始化PixelMap对象数据 + NativePixelMap *native = OH_PixelMap_InitNativePixelMap(env, args[0]); + if (native == nullptr) { + return error; + } + // 获取图片信息 + struct OhosPixelMapInfos pixelMapInfos; + if (OH_PixelMap_GetImageInfo(native, &pixelMapInfos) != IMAGE_RESULT_SUCCESS) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0xFF00, "Test", "Pure : -1"); + return error; + } +// 获取buffer +napi_value buffer = args[1]; +napi_valuetype valueType; +napi_typeof(env, buffer, &valueType); +if (valueType == napi_object) { + bool isArrayBuffer = false; + napi_is_arraybuffer(env, buffer, &isArrayBuffer); + if (!isArrayBuffer) { + napi_throw_error(env, "EINVAL", "Error"); + } +} +void *data = nullptr; +size_t byteLength = 0; +napi_get_arraybuffer_info(env, buffer, &data, &byteLength); +int32_t *saveBuffer = (int32_t *)(data); +// 转换成Mat +cv::Mat originMat(pixelMapInfos.height, pixelMapInfos.width, CV_8UC4, saveBuffer); +if (!originMat.data) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0xFF00, "Read Image", "Pure : -1"); + return error; +} +// opencv默认bgra或bgr,若pixelmap创建时未指定为这两种格式,需要进行格式转换 +cv::Mat saveMat; +cv::cvtColor(originMat, saveMat, cv::COLOR_BGRA2RGBA); +char pathArray[1024]; +size_t length; +napi_get_value_string_utf8(env, args[2], pathArray, 1024, &length); +std::string path(pathArray); +path += "/buffer.jpg"; +if (!cv::imwrite(path, saveMat)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0xFF00, "Write Image", "Pure : -1"); + return error; +} +napi_value res; +napi_create_int32(env, 1, &res); +return res; +} +// DocsCode 2 + +// DocsCode 3 +static napi_value AccessToMat(napi_env env, napi_callback_info info) { + size_t argc = 2; + napi_value args[2] = {nullptr}; + napi_get_cb_info(env, info, &argc, args, nullptr, nullptr); + napi_value error; + napi_create_int32(env, -1, &error); + NativePixelMap *native = OH_PixelMap_InitNativePixelMap(env, args[0]); + if (native == nullptr) { + return error; + } + struct OhosPixelMapInfos pixelMapInfos; + if (OH_PixelMap_GetImageInfo(native, &pixelMapInfos) != IMAGE_RESULT_SUCCESS) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0xFF00, "Test", "Pure : -1"); + return error; + } +void *pixel; +// 获取NativePixelMap对象的内存地址并锁定内存 +OH_PixelMap_AccessPixels(native, &pixel); +// 转换成Mat,注意对齐,所以要传入rowSize +cv::Mat originMat(pixelMapInfos.height, pixelMapInfos.width, CV_8UC4, pixel, pixelMapInfos.rowSize); +if (!originMat.data) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0xFF00, "Read Image", "Pure : -1"); + return error; +} +// opencv默认bgra或bgr,若pixelmap创建时未指定为这两种格式,需要进行格式转换 +cv::Mat saveMat; +cv::cvtColor(originMat, saveMat, cv::COLOR_BGRA2RGBA); +char pathArray[1024]; +size_t length; +napi_get_value_string_utf8(env, args[1], pathArray, 1024, &length); +std::string path(pathArray); +path += "/access.jpg"; +if (!cv::imwrite(path, saveMat)) { + OH_LOG_Print(LOG_APP, LOG_ERROR, 0xFF00, "Write Image", "Pure : -1"); + return error; +} +napi_value res; +napi_create_int32(env, 1, &res); +return res; +} +// DocsCode 3 \ No newline at end of file diff --git a/ImageKit/entry/src/main/ets/pages/Index.ets b/ImageKit/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..8e2d24ad42693fc877d51bb7820f0a9da68fa135 --- /dev/null +++ b/ImageKit/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,23 @@ +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize($r('app.float.page_text_font_size')) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + .onClick(() => { + this.message = 'Welcome'; + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/ImageKit/entry/src/main/ets/pages/PixelMapAndBase64ConverToEachOther.ets b/ImageKit/entry/src/main/ets/pages/PixelMapAndBase64ConverToEachOther.ets new file mode 100644 index 0000000000000000000000000000000000000000..7c31aa2c9776b1fd2fa131a62c39bc7f80224194 --- /dev/null +++ b/ImageKit/entry/src/main/ets/pages/PixelMapAndBase64ConverToEachOther.ets @@ -0,0 +1,96 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:如何实现PixelMap和base64的相互转换 +*/ + +// DocsCode 1 +import { image } from '@kit.ImageKit'; +import { buffer } from '@kit.ArkTS'; + +@Entry +@Component +struct Index { + @State message: string = 'PixelMapToBase64'; + @State base64: string = ''; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + .onClick(async () => { + let resourceManager = this.getUIContext().getHostContext()!.resourceManager + let imageArray = await resourceManager.getMediaContent($r('app.media.sample7')); + let pixelBuffer = new Uint8Array(imageArray).buffer as Object as ArrayBuffer; + let imageResource = image.createImageSource(pixelBuffer); + let opts: image.DecodingOptions = { editable: true } + let pixelMap = await imageResource.createPixelMap(opts); + + // 转换成base64 + const imagePackerApi: image.ImagePacker = image.createImagePacker(); + let packOpts: image.PackingOption = { format: 'image/jpeg', quality: 100 }; + imagePackerApi.packToData(pixelMap, packOpts).then((data: ArrayBuffer) => { + let buf: buffer.Buffer = buffer.from(data); + this.base64 = 'data:image/jpeg;base64,' + buf.toString('base64', 0, buf.length); + console.info('base64: ' + this.base64); + }) + }) + Image(this.base64) + .width(200).height(200).margin(15) + } + .width('100%') + } + .height('100%') + } +} +// DocsCode 1 + +// DocsCode 2 +import CommonConstants from '../common/constants/CommonContants'; +import { util } from '@kit.ArkTS'; +import { image } from '@kit.ImageKit'; + +@Entry +@Component +struct Index { + @State message: string = 'Base64ToPixelMap'; + private base64: string = CommonConstants.Image_Base64_String; // 该变量为图片的base64格式字符串 + @State private pixelMap: PixelMap | null = null; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + .onClick(async () => { + let helper = new util.Base64Helper(); + let buffer: ArrayBuffer = helper.decodeSync(this.base64, util.Type.MIME).buffer as ArrayBuffer; + let imageSource = image.createImageSource(buffer); + let opts: image.DecodingOptions = { editable: true }; + this.pixelMap = await imageSource.createPixelMap(opts); + }) + Image(this.pixelMap) + .width(200).height(200).margin(15) + } + .width('100%') + } + .height('100%') + } +} +// DocsCode 2 \ No newline at end of file diff --git a/ImageKit/entry/src/main/ets/pages/PixelMapSaveToAlbum.ets b/ImageKit/entry/src/main/ets/pages/PixelMapSaveToAlbum.ets new file mode 100644 index 0000000000000000000000000000000000000000..752fe240f343462543d09c578e49725dcd5974d7 --- /dev/null +++ b/ImageKit/entry/src/main/ets/pages/PixelMapSaveToAlbum.ets @@ -0,0 +1,95 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:如何将PixelMap保存到相册 + */ + +// DocsCode 1 +import { resourceManager } from '@kit.LocalizationKit'; +import { photoAccessHelper } from '@kit.MediaLibraryKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { image } from '@kit.ImageKit'; +import { fileIo } from '@kit.CoreFileKit'; + +@Entry +@Component +struct SavePixelMapToAlbum { + @State saveButtonOptions: SaveButtonOptions = { + icon: SaveIconStyle.FULL_FILLED, + text: SaveDescription.SAVE, + buttonType: ButtonType.Capsule + }; + @State pixel: image.PixelMap | undefined = undefined; + @State albumPath: string = ''; + @State photoSize: number = 0; + private context: Context = this.getUIContext().getHostContext()!; + + async aboutToAppear() { + const resourceMgr: resourceManager.ResourceManager = this.context.resourceManager; + // beer.jpeg为rawfile文件下的图片名,可根据自身需求修改使用。 + const fileData: Uint8Array = await resourceMgr.getRawFileContent('beer.jpeg'); + let buffer = new Uint8Array(fileData).buffer as object as ArrayBuffer; + let imageResource = image.createImageSource(buffer); + let opts: image.DecodingOptions = { editable: true }; + this.pixel = await imageResource.createPixelMap(opts); + } + + async savePixelMapToAlbum() { + // 获取相册的保存路径 + let helper = photoAccessHelper.getPhotoAccessHelper(this.context); + let uri = await helper.createAsset(photoAccessHelper.PhotoType.IMAGE, 'jpeg'); + let file = await fileIo.open(uri, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE); + let imagePackerApi = image.createImagePacker(); + let packOpts: image.PackingOption = { format: 'image/jpeg', quality: 98 }; + + imagePackerApi.packToFile(this.pixel, file.fd, packOpts, (err: BusinessError) => { + if (err) { + console.error(`Failed to pack the image to file.code ${err.code},message is ${err.message}`); + } else { + console.info('Succeeded in packing the image to file.'); + imagePackerApi.release((err: BusinessError) => { + if (err) { + console.error(`Failed to release the image source instance.code ${err.code},message is ${err.message}`); + } else { + console.info('Succeeded in releasing the image source instance.'); + fileIo.close(file.fd); + } + }) + this.getUIContext().getPromptAction().showToast({ message: '已保存至相册!' }); + } + }) + } + + build() { + Row() { + Column() { + Image(this.pixel) + .objectFit(ImageFit.None) + .height('30%') + + SaveButton(this.saveButtonOptions) + .onClick(async (event, result: SaveButtonOnClickResult) => { + if (result === SaveButtonOnClickResult.SUCCESS) { + this.savePixelMapToAlbum(); + } + }) + } + .width('100%') + } + .height('100%') + } +} +// DocsCode 1 \ No newline at end of file diff --git a/ImageKit/entry/src/main/ets/pages/ResolveCreatePixelMapError.ets b/ImageKit/entry/src/main/ets/pages/ResolveCreatePixelMapError.ets new file mode 100644 index 0000000000000000000000000000000000000000..75af7653d40dd3734da2b3f81d1576307ee88df2 --- /dev/null +++ b/ImageKit/entry/src/main/ets/pages/ResolveCreatePixelMapError.ets @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:调用imageSource.createPixelMap()报错"Create PixelMap error" + */ + +// DocsCode 1 +const file = fs.openSync(uri, fs.OpenMode.READ_ONLY); +const imageSource = image.createImageSource(file.fd); +const pixelMap = await imageSource.createPixelMap({sampleSize: 2, rotate: 0}); +// DocsCode 1 + +// DocsCode 2 +import { BusinessError } from '@kit.BasicServicesKit'; +import { image } from '@kit.ImageKit'; + +let decodingOptions: image.DecodingOptions = { + editable: true, + desiredPixelFormat: 3, + desiredSize: { width: 4, height: 6 } +} +const context: Context = this.getUIContext().getHostContext()!; +const filePath: string = context.cacheDir + '/test.jpg'; +const imageSource: image.ImageSource = image.createImageSource(filePath); +// 创建pixelMap并进行简单的旋转和缩放 +imageSource.createPixelMap(decodingOptions).then((pixelMap: image.PixelMap) => { + console.log("Succeeded in creating PixelMap") +}).catch((err: BusinessError) => { + console.error("Failed to create PixelMap") +}); +// DocsCode 2 \ No newline at end of file diff --git a/ImageKit/entry/src/main/ets/pages/ResolveErrorCode62980096.ets b/ImageKit/entry/src/main/ets/pages/ResolveErrorCode62980096.ets new file mode 100644 index 0000000000000000000000000000000000000000..ece1b7db0e119e3acdf89dcfc67cd540758aa48e --- /dev/null +++ b/ImageKit/entry/src/main/ets/pages/ResolveErrorCode62980096.ets @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:错误码62980096怎么处理 + */ + +// DocsCode 1 +import { image } from '@kit.ImageKit'; + +@Entry +@Component +struct Index { + @State message: string = 'NV21AndNV12ToPixelMap'; + @State private pixelMap: PixelMap | null = null; + @State private pixelMap2: PixelMap | null = null; + + build() { + Row() { + Column() { + Image(this.pixelMap) + .width(200).height(200).margin(15) + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + .onClick(async () => { + let resourceManager = this.getUIContext().getHostContext()!.resourceManager + let imageArray = await resourceManager.getMediaContent($r("app.media.sample14_NV21_fromJPG_510X510")); + let pixelBuffer = new Uint8Array(imageArray).buffer as Object as ArrayBuffer; + // 其中sourcePixelFormat参数的值8对应NV21格式,9对应NV12格式;sourceSize参数需要设置宽高(原始yuv图片的宽高数据),且width值不能为奇数。 + let sourceOptions: image.SourceOptions = + { sourceDensity: 120, sourcePixelFormat: 8, sourceSize: { width: 510, height: 510 } }; + let imageResource = image.createImageSource(pixelBuffer, sourceOptions); + let opts: image.DecodingOptions = { editable: true } + this.pixelMap = await imageResource.createPixelMap(opts); + + let imageArray2 = await resourceManager.getMediaContent($r('app.media.sample10_NV12_fromJPG_510X510')); + let pixelBuffer2 = new Uint8Array(imageArray2).buffer as Object as ArrayBuffer; + // 其中sourcePixelFormat参数的值8对应NV21格式,9对应NV12格式;sourceSize参数需要设置宽高(原始yuv图片的宽高数据),且width值不能为奇数。 + let sourceOptions2: image.SourceOptions = + { sourceDensity: 120, sourcePixelFormat: 9, sourceSize: { width: 510, height: 510 } }; + let imageResource2 = image.createImageSource(pixelBuffer2, sourceOptions2); + let opts2: image.DecodingOptions = { editable: true } + this.pixelMap2 = await imageResource2.createPixelMap(opts2); + }) + Image(this.pixelMap2) + .width(200).height(200).margin(15) + } + .width('100%') + } + .height('100%') + } +} +// DocsCode 1 \ No newline at end of file diff --git a/ImageKit/entry/src/main/ets/pages/SaveVideoFrameDataLocally.ets b/ImageKit/entry/src/main/ets/pages/SaveVideoFrameDataLocally.ets new file mode 100644 index 0000000000000000000000000000000000000000..a4f8c8edc473db19aff9e21942f308f997d709dc --- /dev/null +++ b/ImageKit/entry/src/main/ets/pages/SaveVideoFrameDataLocally.ets @@ -0,0 +1,68 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:如何把ImageReceiver收到的视频帧数据保存到本地 + */ + +// DocsCode 1 +let size: image.Size = { + width: 640, + height: 480 +} +let receiver: image.ImageReceiver = image.createImageReceiver(size, image.ImageFormat.JPEG, 8); +receiver.on('imageArrival', () => { + console.info("imageArrival callback"); + receiver.readNextImage((err: BusinessError, nextImage: image.Image) => { + if (err || nextImage === undefined) { + console.error("receiveImage -error:" + err + " nextImage:" + nextImage); + return; + } + nextImage.getComponent(image.ComponentType.JPEG, (err: BusinessError, imgComponent: image.Component) => { + if (err || imgComponent === undefined) { + console.error("receiveImage--getComponent -error:" + err + " imgComponent:" + imgComponent); + return; + } + + if (imgComponent.byteBuffer as ArrayBuffer) { + let sourceOptions: image.SourceOptions = { + sourceDensity: 120, + sourcePixelFormat: 8, + sourceSize: { + height: 1080, + width: 1920 + }, + } + let imageResource = image.createImageSource(imgComponent.byteBuffer, sourceOptions); + let imagePackerApi = image.createImagePacker(); + let packOpts: image.PackingOption = { format: "image/jpeg", quality: 90 }; + const filePath: string = this.getUIContext().getHostContext()!.cacheDir + "/image.jpg"; + let file = fs.openSync(filePath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); + imagePackerApi.packToFile(imageResource, file.fd, packOpts).then(() => { + console.error('pack success: ' + filePath); + }).catch((error: BusinessError) => { + console.error('Failed to pack the image. And the error is: ' + error); + }) + imageResource.createPixelMap({}).then((res) => { + this.imgUrl = res; + }); + } else { + return; + } + nextImage.release(); + }); + }); +}); +// DocsCode 1 \ No newline at end of file diff --git a/ImageKit/entry/src/main/ets/pages/SaveWebPictureToAlbum.ets b/ImageKit/entry/src/main/ets/pages/SaveWebPictureToAlbum.ets new file mode 100644 index 0000000000000000000000000000000000000000..448ac95614a16df3ed66e3fae7581494228f01b2 --- /dev/null +++ b/ImageKit/entry/src/main/ets/pages/SaveWebPictureToAlbum.ets @@ -0,0 +1,118 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:如何保存网络图片到相册 +*/ + +// DocsCode 1 +import { http } from '@kit.NetworkKit'; +import { image } from '@kit.ImageKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { photoAccessHelper } from '@kit.MediaLibraryKit'; +import { promptAction } from '@kit.ArkUI'; +import { fileIo as fs } from '@kit.CoreFileKit'; + +@Entry +@Component +struct SaveImage { + @State pixelMap: PixelMap | undefined = undefined; + + loadImageWithUrl(url: string) { + let responseCode = http.ResponseCode; + let OutData: http.HttpResponse; + let imagePackerApi = image.createImagePacker(); + let packOpts: image.PackingOption = { format: 'image/jpeg', quality: 98 }; + // 确保网络正常 + http.createHttp().request(url, { + method: http.RequestMethod.GET, + connectTimeout: 60000, + readTimeout: 60000 + }, + async (error: BusinessError, data: http.HttpResponse) => { + if (error) { + console.error(`http request failed with. Code: ${error.code}, message: ${error.message}`); + } else { + OutData = data; + let code: http.ResponseCode | number = OutData.responseCode; + if (responseCode.OK === code) { + let imageData: ArrayBuffer = OutData.result as ArrayBuffer; + let imageSource: image.ImageSource = image.createImageSource(imageData); + + class tmp { + height: number = 100 + width: number = 100 + }; + + let options: Record = { + 'alphaType': 0, // 透明度 + 'editable': false, // 是否可编辑 + 'pixelFormat': 3, // 像素格式 + 'scaleMode': 1, // 缩略值 + 'size': { height: 100, width: 100 } + }; // 创建图片大小 + imageSource.createPixelMap(options).then((pixelMap: PixelMap) => { + this.pixelMap = pixelMap; + this.pixelMap.getImageInfo().then((info: image.ImageInfo) => { + console.info('info.width = ' + info.size.width); + }).catch((err: BusinessError) => { + console.error('Failed ' + err); + }) + imagePackerApi.packToData(pixelMap, packOpts).then(async (buffer: ArrayBuffer) => { + try { + const context = this.getUIContext().getHostContext()!; + let helper = photoAccessHelper.getPhotoAccessHelper(context); + let uri = await helper.createAsset(photoAccessHelper.PhotoType.IMAGE, 'png'); + let file = await fs.open(uri, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); + // 写入文件 + await fs.write(file.fd, buffer); + promptAction.showToast({ message: '已保存至相册!' }); + // 关闭文件 + await fs.close(file.fd); + } catch (error) { + console.error('error is ' + JSON.stringify(error)); + } + }).catch((error: BusinessError) => { + console.error('Failed to pack the image. And the error is: ' + error); + }) + pixelMap.release(); + }) + } + } + } + ) + } + + build() { + Row() { + Column({ space: 10 }) { + Image('https://agc-storage-drcn.platform.dbankcloud.cn/v0/test-rqcjj/test.png') + .width('80%') + + SaveButton().onClick(async (event: ClickEvent, result: SaveButtonOnClickResult) => { + if (result === SaveButtonOnClickResult.SUCCESS) { + this.loadImageWithUrl('https://agc-storage-drcn.platform.dbankcloud.cn/v0/test-rqcjj/test.png'); + } else { + promptAction.showToast({ message: '设置权限失败!' }); + } + }) + } + .width('100%') + } + .height('100%') + .backgroundColor(0xF1F3F5) + } +} +// DocsCode 1 \ No newline at end of file diff --git a/ImageKit/entry/src/main/ets/pages/SelectedAlbumPictureGeneratePixelMap.ets b/ImageKit/entry/src/main/ets/pages/SelectedAlbumPictureGeneratePixelMap.ets new file mode 100644 index 0000000000000000000000000000000000000000..d963559a697acfc7fb8bd34ab5c1ab47a684b954 --- /dev/null +++ b/ImageKit/entry/src/main/ets/pages/SelectedAlbumPictureGeneratePixelMap.ets @@ -0,0 +1,130 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:如何将相册选择的图片生成PixelMap +*/ + +// DocsCode 1 +import { photoAccessHelper } from '@kit.MediaLibraryKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { dataSharePredicates } from '@kit.ArkData'; +import { common } from '@kit.AbilityKit'; + +const context = UIContext.getHostContext() as common.UIAbilityContext; +@Entry +@Component +struct WebComponent { + build() { + Column() { + Button('选择图片').onClick(() => { + try { + let uris: Array = []; + let PhotoSelectOptions = new photoAccessHelper.PhotoSelectOptions(); + PhotoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE; + PhotoSelectOptions.maxSelectNumber = 1; + let photoPicker = new photoAccessHelper.PhotoViewPicker(); + photoPicker.select(PhotoSelectOptions).then((PhotoSelectResult: photoAccessHelper.PhotoSelectResult) => { + console.info('photoPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult)); + uris = PhotoSelectResult.photoUris; + let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); + let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); + // 配置查询条件,使用PhotoViewPicker选择图片返回的uri进行查询 + predicates.equalTo('uri', uris[0]); + let fetchOptions: photoAccessHelper.FetchOptions = { + fetchColumns: [], + predicates: predicates + }; + phAccessHelper.getAssets(fetchOptions, async (err, fetchResult) => { + if (fetchResult !== undefined) { + console.info('fetchResult success'); + let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); + if (photoAsset !== undefined) { + // 获取缩略图 + photoAsset.getThumbnail((err, pixelMap) => { + if (err == undefined) { + console.info('getThumbnail successful ' + JSON.stringify(pixelMap)); + } else { + console.error('getThumbnail fail', err); + } + }); + console.info('photoAsset.displayName : ' + photoAsset.displayName); + } + } else { + console.error(`fetchResult fail with error: ${err.code}, ${err.message}`); + } + }); + }).catch((err: BusinessError) => { + console.error('photoPicker.select failed with err: ' + JSON.stringify(err)); + }); + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error('photoPicker failed with err: ' + JSON.stringify(err)); + } + }) + } + } +} +// DocsCode 1 + +// DocsCode 2 +import { photoAccessHelper } from '@kit.MediaLibraryKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { image } from '@kit.ImageKit'; +import { fileIo } from '@kit.CoreFileKit'; + +@Entry +@Component +struct WebComponent { + build() { + Column() { + Button('选择图片').onClick(() => { + try { + let uris: Array = []; + let PhotoSelectOptions = new photoAccessHelper.PhotoSelectOptions(); + PhotoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE; + PhotoSelectOptions.maxSelectNumber = 1; + let photoPicker = new photoAccessHelper.PhotoViewPicker(); + photoPicker.select(PhotoSelectOptions).then((PhotoSelectResult: photoAccessHelper.PhotoSelectResult) => { + uris = PhotoSelectResult.photoUris; + let file = fileIo.openSync(uris[0], fileIo.OpenMode.READ_ONLY); + console.info('file fd: ' + file.fd); + let buffer = new ArrayBuffer(4096); + let readLen = fileIo.readSync(file.fd, buffer); + console.info('readSync data to file succeed and buffer size is:' + readLen); + const imageSource: image.ImageSource = image.createImageSource(file.fd); + let decodingOptions: image.DecodingOptions = { + editable: true, + desiredPixelFormat: 3, + } + imageSource.createPixelMap(decodingOptions, (err: BusinessError, pixelMap: image.PixelMap) => { + if (err !== undefined) { + console.error(`Failed to create pixelMap.code is ${err.code},message is ${err.message}`); + } else { + console.info('Succeeded in creating pixelMap object.'); + } + }) + }).catch((err: BusinessError) => { + console.error(`Invoke photoPicker.select failed, code is ${err.code}, message is ${err.message}`); + }) + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error('photoPicker failed with err: ' + JSON.stringify(err)); + } + }) + } + } +} +// DocsCode 2 \ No newline at end of file diff --git a/ImageKit/entry/src/main/module.json5 b/ImageKit/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a1cea8b6a4560cee7bda7a2db52f310c035ab6c8 --- /dev/null +++ b/ImageKit/entry/src/main/module.json5 @@ -0,0 +1,52 @@ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/ImageKit/entry/src/main/resources/base/element/color.json b/ImageKit/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/ImageKit/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/ImageKit/entry/src/main/resources/base/element/float.json b/ImageKit/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..a0a93dd91fd48f08f3a9532c76e9b26e68d4c034 --- /dev/null +++ b/ImageKit/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} \ No newline at end of file diff --git a/ImageKit/entry/src/main/resources/base/element/string.json b/ImageKit/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/ImageKit/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/ImageKit/entry/src/main/resources/base/media/background.png b/ImageKit/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/ImageKit/entry/src/main/resources/base/media/background.png differ diff --git a/ImageKit/entry/src/main/resources/base/media/foreground.png b/ImageKit/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/ImageKit/entry/src/main/resources/base/media/foreground.png differ diff --git a/ImageKit/entry/src/main/resources/base/media/layered_image.json b/ImageKit/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ImageKit/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ImageKit/entry/src/main/resources/base/media/startIcon.png b/ImageKit/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ImageKit/entry/src/main/resources/base/media/startIcon.png differ diff --git a/ImageKit/entry/src/main/resources/base/profile/backup_config.json b/ImageKit/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/ImageKit/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/ImageKit/entry/src/main/resources/base/profile/main_pages.json b/ImageKit/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..bf3989d6e57eeeb1cb5f8a619ba2f96183c3984f --- /dev/null +++ b/ImageKit/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,12 @@ +{ + "src": [ + "pages/Index", + "pages/PixelMapAndBase64ConverToEachOther", + "pages/SaveWebPictureToAlbum", + "pages/SelectedAlbumPictureGeneratePixelMap", + "pages/ResolveCreatePixelMapError", + "pages/SaveVideoFrameDataLocally", + "pages/ResolveErrorCode62980096", + "pages/ConvertPixelMapToCvMatFormat" + ] +} \ No newline at end of file diff --git a/ImageKit/entry/src/main/resources/dark/element/color.json b/ImageKit/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/ImageKit/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/ImageKit/entry/src/mock/mock-config.json5 b/ImageKit/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7a73a41bfdf76d6f793007240d80983a52f15f97 --- /dev/null +++ b/ImageKit/entry/src/mock/mock-config.json5 @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/ImageKit/entry/src/ohosTest/ets/test/Ability.test.ets b/ImageKit/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..85c78f67579d6e31b5f5aeea463e216b9b141048 --- /dev/null +++ b/ImageKit/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,35 @@ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + }) +} \ No newline at end of file diff --git a/ImageKit/entry/src/ohosTest/ets/test/List.test.ets b/ImageKit/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..794c7dc4ed66bd98fa3865e07922906e2fcef545 --- /dev/null +++ b/ImageKit/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,5 @@ +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/ImageKit/entry/src/ohosTest/module.json5 b/ImageKit/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..55725a929993a8a18b3808d41ef037759440488b --- /dev/null +++ b/ImageKit/entry/src/ohosTest/module.json5 @@ -0,0 +1,13 @@ +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/ImageKit/entry/src/test/List.test.ets b/ImageKit/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..bb5b5c3731e283dd507c847560ee59bde477bbc7 --- /dev/null +++ b/ImageKit/entry/src/test/List.test.ets @@ -0,0 +1,5 @@ +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/ImageKit/entry/src/test/LocalUnit.test.ets b/ImageKit/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..165fc1615ee8618b4cb6a622f144a9a707eee99f --- /dev/null +++ b/ImageKit/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,33 @@ +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/ImageKit/hvigor/hvigor-config.json5 b/ImageKit/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a63d34ae5ce5833b3874807e2b8d472687c6c5bf --- /dev/null +++ b/ImageKit/hvigor/hvigor-config.json5 @@ -0,0 +1,22 @@ +{ + "modelVersion": "5.0.4", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/ImageKit/hvigorfile.ts b/ImageKit/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..f3cb9f1a87a81687554a76283af8df27d8bda775 --- /dev/null +++ b/ImageKit/hvigorfile.ts @@ -0,0 +1,6 @@ +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/ImageKit/oh-package-lock.json5 b/ImageKit/oh-package-lock.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7fcf818273347b97063c0c0a151bb14770ca1c79 --- /dev/null +++ b/ImageKit/oh-package-lock.json5 @@ -0,0 +1,27 @@ +{ + "meta": { + "stableOrder": true + }, + "lockfileVersion": 3, + "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", + "specifiers": { + "@ohos/hamock@1.0.0": "@ohos/hamock@1.0.0", + "@ohos/hypium@1.0.21": "@ohos/hypium@1.0.21" + }, + "packages": { + "@ohos/hamock@1.0.0": { + "name": "@ohos/hamock", + "version": "1.0.0", + "integrity": "sha512-K6lDPYc6VkKe6ZBNQa9aoG+ZZMiwqfcR/7yAVFSUGIuOAhPvCJAo9+t1fZnpe0dBRBPxj2bxPPbKh69VuyAtDg==", + "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hamock/-/hamock-1.0.0.har", + "registryType": "ohpm" + }, + "@ohos/hypium@1.0.21": { + "name": "@ohos/hypium", + "version": "1.0.21", + "integrity": "sha512-iyKGMXxE+9PpCkqEwu0VykN/7hNpb+QOeIuHwkmZnxOpI+dFZt6yhPB7k89EgV1MiSK/ieV/hMjr5Z2mWwRfMQ==", + "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hypium/-/hypium-1.0.21.har", + "registryType": "ohpm" + } + } +} \ No newline at end of file diff --git a/ImageKit/oh-package.json5 b/ImageKit/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..75e4e229db0f608fc3d9471c8819d0e52fb403c5 --- /dev/null +++ b/ImageKit/oh-package.json5 @@ -0,0 +1,10 @@ +{ + "modelVersion": "5.0.4", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.21", + "@ohos/hamock": "1.0.0" + } +}