diff --git a/OAT.xml b/OAT.xml
index fb2b2507c7e18d6f832870e95c5c39323ce4b8a2..8c9842e9ed6a58789c5f21add8b50fbbae20560e 100644
--- a/OAT.xml
+++ b/OAT.xml
@@ -430,6 +430,8 @@ Note:If the text contains special characters, please escape them according to th
+
+
diff --git a/code/DocsSample/Media/Image/NdkPicture/.gitignore b/code/DocsSample/Media/Image/NdkPicture/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/.gitignore
@@ -0,0 +1,12 @@
+/node_modules
+/oh_modules
+/local.properties
+/.idea
+**/build
+/.hvigor
+.cxx
+/.clangd
+/.clang-format
+/.clang-tidy
+**/.test
+/.appanalyzer
\ No newline at end of file
diff --git a/code/DocsSample/Media/Image/NdkPicture/AppScope/app.json5 b/code/DocsSample/Media/Image/NdkPicture/AppScope/app.json5
new file mode 100644
index 0000000000000000000000000000000000000000..2da0cb584c179b8c7619d1b1aa840eab7ee646eb
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/AppScope/app.json5
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2025 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.
+ */
+{
+ "app": {
+ "bundleName": "com.samples.ndkpicture",
+ "vendor": "example",
+ "versionCode": 1000000,
+ "versionName": "1.0.0",
+ "icon": "$media:layered_image",
+ "label": "$string:app_name"
+ }
+}
\ No newline at end of file
diff --git a/code/DocsSample/Media/Image/NdkPicture/AppScope/resources/base/element/string.json b/code/DocsSample/Media/Image/NdkPicture/AppScope/resources/base/element/string.json
new file mode 100644
index 0000000000000000000000000000000000000000..86426c28cf3b0aa0617d9dded26fdae7a7359ced
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/AppScope/resources/base/element/string.json
@@ -0,0 +1,8 @@
+{
+ "string": [
+ {
+ "name": "app_name",
+ "value": "NdkPicture"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/code/DocsSample/Media/Image/NdkPicture/AppScope/resources/base/media/background.png b/code/DocsSample/Media/Image/NdkPicture/AppScope/resources/base/media/background.png
new file mode 100644
index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f
Binary files /dev/null and b/code/DocsSample/Media/Image/NdkPicture/AppScope/resources/base/media/background.png differ
diff --git a/code/DocsSample/Media/Image/NdkPicture/AppScope/resources/base/media/foreground.png b/code/DocsSample/Media/Image/NdkPicture/AppScope/resources/base/media/foreground.png
new file mode 100644
index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f
Binary files /dev/null and b/code/DocsSample/Media/Image/NdkPicture/AppScope/resources/base/media/foreground.png differ
diff --git a/code/DocsSample/Media/Image/NdkPicture/AppScope/resources/base/media/layered_image.json b/code/DocsSample/Media/Image/NdkPicture/AppScope/resources/base/media/layered_image.json
new file mode 100644
index 0000000000000000000000000000000000000000..4f9ad6307a2bc56beb6d0fce0a49cbf213b20a74
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/AppScope/resources/base/media/layered_image.json
@@ -0,0 +1,6 @@
+{
+ "layered-image": {
+ "background": "$media:background",
+ "foreground": "$media:foreground"
+ }
+}
\ No newline at end of file
diff --git a/code/DocsSample/Media/Image/NdkPicture/README.md b/code/DocsSample/Media/Image/NdkPicture/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..15bb7fc68d6cf8f9c85344438a4b948e41d3c68c
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/README.md
@@ -0,0 +1,74 @@
+# NdkPicture
+
+## 介绍
+本示例主要实现了基于Picture的图片解码、主图获取、图片编码等功能。
+
+## 效果预览
+
+| 主界面 |
+| ---------------------------------------------- |
+|  |
+
+使用说明:
+
+1. 点击'Create Picture'按钮,解码图片,并以弹窗的形式通知结果(是否解码成功)。
+2. 点击'Get MainPixelMap'按钮,从解码的Picture中获取主图,并以弹窗的形式通知结果。
+3. 点击'Pack To Data'按钮或'Pack To File'按钮,将Picture编码到缓冲区或图片文件,并以弹窗的形式通知结果。
+4. 点击'Realease Picture'按钮,释放Picture对象。
+
+## 工程目录
+
+```
+NdkPicture
+entry/src/main/cpp/
+├── types
+│ └── libentry
+│ └── Index.d.ts (声明Napi接口,供ts调用)
+├── CMakeLists.txt (CMake编译配置文件)
+└── napi_init.cpp (初始化Napi接口)
+entry/src/main/ets/
+├── utils
+│ └── Logger.ets (logger日志类)
+│ └── MyButton.ets (自定义Button按钮类)
+│ └── PictureFunctions.ets (Picture函数类)
+└── pages
+ └── Index.ets (UI界面)
+entry/src/main/resources/
+└── rawfile
+ └── test.jpg(图片资源)
+entry/src/ohosTest/ets/
+└── test
+ ├── Ability.test.ets (UI测试代码)
+ └── List.test.ets (测试套件列表)
+```
+
+## 具体实现
++ 图片解码、获取主图、图片编码等功能的CPAI封装均在napi_init中实现,源码参考[napi_init.cpp](./entry/src/main/cpp/napi_init.cpp)。
+
+## 相关权限
+
+不涉及
+
+## 依赖
+
+不涉及
+
+## 约束和限制
+
+1. 本示例支持标准系统上运行,支持设备:RK3568;
+
+2. 本示例支持API15版本SDK,版本号:5.0.3.135;
+
+3. 本示例已支持使DevEco Studio 5.0.3 Release (构建版本:5.0.8.300,构建 2025年3月19日)编译运行
+
+## 下载
+
+如需单独下载本工程,执行如下命令:
+
+```
+git init
+git config core.sparsecheckout true
+echo code/DocsSample/Media/Image/NdkPicture/ > .git/info/sparse-checkout
+git remote add origin OpenHarmony/applications_app_samples
+git pull origin master
+```
\ No newline at end of file
diff --git a/code/DocsSample/Media/Image/NdkPicture/build-profile.json5 b/code/DocsSample/Media/Image/NdkPicture/build-profile.json5
new file mode 100644
index 0000000000000000000000000000000000000000..1be9d2a570766548232f7292e26e5d2d323d9ab9
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/build-profile.json5
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2025 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.
+ */
+{
+ "app": {
+ "signingConfigs": [
+ ],
+ "products": [
+ {
+ "name": "default",
+ "signingConfig": "default",
+ "compileSdkVersion": 15,
+ "targetSdkVersion": 15,
+ "compatibleSdkVersion": 15,
+ "runtimeOS": "OpenHarmony",
+ "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/code/DocsSample/Media/Image/NdkPicture/code-linter.json5 b/code/DocsSample/Media/Image/NdkPicture/code-linter.json5
new file mode 100644
index 0000000000000000000000000000000000000000..073990fa45394e1f8e85d85418ee60a8953f9b99
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/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/code/DocsSample/Media/Image/NdkPicture/entry/.gitignore b/code/DocsSample/Media/Image/NdkPicture/entry/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/entry/.gitignore
@@ -0,0 +1,6 @@
+/node_modules
+/oh_modules
+/.preview
+/build
+/.cxx
+/.test
\ No newline at end of file
diff --git a/code/DocsSample/Media/Image/NdkPicture/entry/build-profile.json5 b/code/DocsSample/Media/Image/NdkPicture/entry/build-profile.json5
new file mode 100644
index 0000000000000000000000000000000000000000..7ddb49d18026714e9bbca59e42790065cdb434e9
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/entry/build-profile.json5
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2025 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.
+ */
+{
+ "apiType": "stageMode",
+ "buildOption": {
+ "externalNativeOptions": {
+ "path": "./src/main/cpp/CMakeLists.txt",
+ "arguments": "",
+ "cppFlags": "",
+ "abiFilters": [
+ "arm64-v8a",
+ "x86_64",
+ "armeabi-v7a"
+ ]
+ }
+ },
+ "buildOptionSet": [
+ {
+ "name": "release",
+ "arkOptions": {
+ "obfuscation": {
+ "ruleOptions": {
+ "enable": false,
+ "files": [
+ "./obfuscation-rules.txt"
+ ]
+ }
+ }
+ },
+ "nativeLib": {
+ "debugSymbol": {
+ "strip": true,
+ "exclude": []
+ }
+ }
+ },
+ ],
+ "targets": [
+ {
+ "name": "default"
+ },
+ {
+ "name": "ohosTest",
+ }
+ ]
+}
\ No newline at end of file
diff --git a/code/DocsSample/Media/Image/NdkPicture/entry/hvigorfile.ts b/code/DocsSample/Media/Image/NdkPicture/entry/hvigorfile.ts
new file mode 100644
index 0000000000000000000000000000000000000000..c6edcd90486dd5a853cf7d34c8647f08414ca7a3
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/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/code/DocsSample/Media/Image/NdkPicture/entry/obfuscation-rules.txt b/code/DocsSample/Media/Image/NdkPicture/entry/obfuscation-rules.txt
new file mode 100644
index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/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/code/DocsSample/Media/Image/NdkPicture/entry/oh-package.json5 b/code/DocsSample/Media/Image/NdkPicture/entry/oh-package.json5
new file mode 100644
index 0000000000000000000000000000000000000000..5b21e253af246edab8b6ef4f10938f4417e8bc25
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/entry/oh-package.json5
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2025 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.
+ */
+{
+ "name": "entry",
+ "version": "1.0.0",
+ "description": "Please describe the basic information.",
+ "main": "",
+ "author": "",
+ "license": "",
+ "dependencies": {
+ "libentry.so": "file:./src/main/cpp/types/libentry"
+ }
+}
\ No newline at end of file
diff --git a/code/DocsSample/Media/Image/NdkPicture/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/cpp/CMakeLists.txt
new file mode 100644
index 0000000000000000000000000000000000000000..ce4f206e4a3c8bf11ef23bbac4686ec93bd7e153
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/cpp/CMakeLists.txt
@@ -0,0 +1,24 @@
+# the minimum version of CMake.
+cmake_minimum_required(VERSION 3.5.0)
+project(NdkPictur)
+
+set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
+
+if(DEFINED PACKAGE_FIND_FILE)
+ include(${PACKAGE_FIND_FILE})
+endif()
+
+include_directories(${NATIVERENDER_ROOT_PATH}
+ ${NATIVERENDER_ROOT_PATH}/include)
+
+add_library(entry SHARED napi_init.cpp)
+
+target_link_libraries(entry PUBLIC
+ libace_napi.z.so
+ libhilog_ndk.z.so
+ libohimage.so
+ libimage_source.so
+ libpicture.so
+ libimage_common.so
+ libimage_packer.so
+)
\ No newline at end of file
diff --git a/code/DocsSample/Media/Image/NdkPicture/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/cpp/napi_init.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..fcf5641296215207c2b0a4249df102801f6cd0c1
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/cpp/napi_init.cpp
@@ -0,0 +1,540 @@
+/*
+ * Copyright (c) 2025 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.
+ */
+
+#include "napi/native_api.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#define IMG_IS_OK(x) ((x) == napi_ok)
+
+#define IMG_NAPI_CHECK_RET_D(x, res, msg) \
+ do { \
+ if (!(x)) { \
+ msg; \
+ return (res); \
+ } \
+ } while (0)
+
+#define IMG_JS_ARGS(env, info, status, argc, argv, thisVar) \
+ do { \
+ status = napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr); \
+ } while (0)
+
+#define H_LOGI(...) ((void)OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, APP_LOG_TAG, __VA_ARGS__))
+#define H_LOGD(...) ((void)OH_LOG_Print(LOG_APP, LOG_DEBUG, LOG_DOMAIN, APP_LOG_TAG, __VA_ARGS__))
+#define H_LOGW(...) ((void)OH_LOG_Print(LOG_APP, LOG_WARNING, LOG_DOMAIN, APP_LOG_TAG, __VA_ARGS__))
+#define H_LOGE(format, ...) \
+ OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_DOMAIN, APP_LOG_TAG, "%{public}s:%{public}s:%{public}d: " format, \
+ __FILE_NAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
+
+const char *APP_LOG_TAG = "MultiMediaImage";
+const char *PROJECT_TAG = "[NdkPicture]";
+
+class ImagePictureNative {
+public:
+ Image_ErrorCode errCode_ = IMAGE_SUCCESS;
+ OH_DecodingOptionsForPicture *options_ = nullptr;
+ OH_ImagePackerNative *imagePacker_ = nullptr;
+ OH_PackingOptions *packerOptions_ = nullptr;
+ OH_AuxiliaryPictureNative *auxiliaryPicture_ = nullptr;
+ OH_AuxiliaryPictureNative *gainMapAuxiliaryPicture_ = nullptr;
+ OH_PictureNative *picture_ = nullptr;
+ OH_PictureNative *pictureByImageSource = nullptr;
+ OH_AuxiliaryPictureInfo *info_ = nullptr;
+ OH_PictureMetadata *Metadata_ = nullptr;
+ OH_PictureMetadata *newMetadata_ = nullptr;
+ OH_ImageSourceNative *source_ = nullptr;
+ OH_PixelmapNative *resPixMap_ = nullptr;
+ ImagePictureNative() {}
+ ~ImagePictureNative() {}
+};
+static ImagePictureNative *ndkPicture_ = new ImagePictureNative();
+
+// 将int类型的返回值转换为napi_value类型
+napi_value getJsResult(napi_env env, int result) {
+ napi_value resultNapi = nullptr;
+ napi_create_int32(env, result, &resultNapi);
+ return resultNapi;
+}
+
+// 传入图片文件路径,解码得到PixelMap
+Image_ErrorCode CreatePixelmap(char filePath[1024], size_t filePathSize) {
+ if (ndkPicture_->source_ != nullptr) {
+ OH_ImageSourceNative_Release(ndkPicture_->source_);
+ ndkPicture_->source_ = nullptr;
+ }
+
+ ndkPicture_->errCode_ = OH_ImageSourceNative_CreateFromUri(filePath, filePathSize, &ndkPicture_->source_);
+ if (ndkPicture_->errCode_ != IMAGE_SUCCESS) {
+ H_LOGE("%{public}s OH_ImageSourceNative_CreateFromUri failed, errCode: %{public}d.", PROJECT_TAG,
+ ndkPicture_->errCode_);
+ return ndkPicture_->errCode_;
+ } else {
+ H_LOGI("%{public}s OH_ImageSourceNative_CreateFromUri success !", PROJECT_TAG);
+ }
+
+ OH_DecodingOptions *ops = nullptr;
+ OH_DecodingOptions_Create(&ops);
+ ndkPicture_->errCode_ = OH_ImageSourceNative_CreatePixelmap(ndkPicture_->source_, ops, &ndkPicture_->resPixMap_);
+ OH_DecodingOptions_Release(ops);
+ if (ndkPicture_->errCode_ != IMAGE_SUCCESS) {
+ H_LOGE("%{public}s OH_ImageSourceNative_CreatePixelmap failed, errCode: %{public}d.", PROJECT_TAG,
+ ndkPicture_->errCode_);
+ return ndkPicture_->errCode_;
+ } else {
+ H_LOGI("%{public}s OH_ImageSourceNative_CreatePixelmap success !", PROJECT_TAG);
+ }
+ return ndkPicture_->errCode_;
+}
+
+// 使用PixelMap创建Picture,通过这种方式创建的Picture仅包含主图
+static napi_value CreatePicture(napi_env env, napi_callback_info info) {
+ size_t argc = 1;
+ napi_value args[1] = {nullptr};
+ napi_value result = nullptr;
+
+ if (napi_get_cb_info(env, info, &argc, args, nullptr, nullptr) != napi_ok || argc < 1 || args[0] == nullptr) {
+ H_LOGE("%{public}s CreatePicture_ napi_get_cb_info failed !", PROJECT_TAG);
+ return getJsResult(env, IMAGE_BAD_PARAMETER);
+ }
+
+ char filePath[1024];
+ size_t filePathSize;
+ napi_get_value_string_utf8(env, args[0], filePath, 1024, &filePathSize);
+
+ ndkPicture_->errCode_ = CreatePixelmap(filePath, filePathSize);
+ if (ndkPicture_->picture_ != nullptr) {
+ ndkPicture_->errCode_ = OH_PictureNative_Release(ndkPicture_->picture_);
+ ndkPicture_->picture_ = nullptr;
+ }
+ if (ndkPicture_->errCode_ != IMAGE_SUCCESS) {
+ H_LOGE("%{public}s CreatePicture_ OH_PictureNative_Release failed, errCode: %{public}d.", PROJECT_TAG,
+ ndkPicture_->errCode_);
+ return getJsResult(env, ndkPicture_->errCode_);
+ }
+
+ ndkPicture_->errCode_ = OH_PictureNative_CreatePicture(ndkPicture_->resPixMap_, &ndkPicture_->picture_);
+
+ if (ndkPicture_->errCode_ != IMAGE_SUCCESS) {
+ H_LOGE("%{public}s OH_PictureNative_CreatePicture failed, errCode: %{public}d.", PROJECT_TAG,
+ ndkPicture_->errCode_);
+ return getJsResult(env, ndkPicture_->errCode_);
+ ;
+ } else {
+ napi_status status =
+ napi_create_external(env, reinterpret_cast(ndkPicture_->picture_), nullptr, nullptr, &result);
+ if (status != napi_ok) {
+ napi_throw_error(env, nullptr, "Failed to create external object");
+ return getJsResult(env, ndkPicture_->errCode_);
+ }
+ H_LOGI("%{public}s OH_PictureNative_CreatePicture success !", PROJECT_TAG);
+ }
+
+ return getJsResult(env, ndkPicture_->errCode_);
+}
+
+// 使用ImageSource创建Picture,通过这种方式创建的Picture会包含主图、辅助图、元数据(如果原图有辅助图和元数据)
+static napi_value CreatePictureByImageSource(napi_env env, napi_callback_info info) {
+ size_t argc = 1;
+ napi_value args[1] = {nullptr};
+ napi_value result = nullptr;
+
+ if (napi_get_cb_info(env, info, &argc, args, nullptr, nullptr) != napi_ok || argc < 1 || args[0] == nullptr) {
+ H_LOGE("%{public}s CreatePicture_ napi_get_cb_info failed !", PROJECT_TAG);
+ return getJsResult(env, IMAGE_BAD_PARAMETER);
+ }
+ char filePath[1024];
+ size_t filePathSize;
+ napi_get_value_string_utf8(env, args[0], filePath, 1024, &filePathSize);
+
+ if (ndkPicture_->source_ != nullptr) {
+ OH_ImageSourceNative_Release(ndkPicture_->source_);
+ ndkPicture_->source_ = nullptr;
+ }
+
+ ndkPicture_->errCode_ = OH_ImageSourceNative_CreateFromUri(filePath, filePathSize, &ndkPicture_->source_);
+ if (ndkPicture_->errCode_ != IMAGE_SUCCESS) {
+ H_LOGE("%{public}s OH_ImageSourceNative_CreateFromUri failed, errCode: %{public}d.", PROJECT_TAG,
+ ndkPicture_->errCode_);
+ return getJsResult(env, ndkPicture_->errCode_);
+ } else {
+ H_LOGI("%{public}s OH_ImageSourceNative_CreateFromUri success !", PROJECT_TAG);
+ }
+ OH_DecodingOptions *ops = nullptr;
+ OH_DecodingOptions_Create(&ops);
+ ndkPicture_->errCode_ = OH_ImageSourceNative_CreatePicture(ndkPicture_->source_, ndkPicture_->options_,
+ &ndkPicture_->pictureByImageSource);
+ if (ndkPicture_->errCode_ != IMAGE_SUCCESS) {
+ H_LOGE("%{public}s ImageSourceNative_CreatePicture failed, errCode: %{public}d.", PROJECT_TAG,
+ ndkPicture_->errCode_);
+ return getJsResult(env, ndkPicture_->errCode_);
+ } else {
+ napi_status status = napi_create_external(env, reinterpret_cast(ndkPicture_->pictureByImageSource),
+ nullptr, nullptr, &result);
+ if (status != napi_ok) {
+ napi_throw_error(env, nullptr, "Failed to create external object");
+ return getJsResult(env, ndkPicture_->errCode_);
+ }
+ H_LOGI("%{public}s ImageSourceNative_CreatePicture success !", PROJECT_TAG);
+ }
+
+ return getJsResult(env, ndkPicture_->errCode_);
+}
+
+// 获取主图
+static napi_value GetMainPixelMap(napi_env env, napi_callback_info info) {
+ napi_value result = nullptr;
+ OH_PixelmapNative *mainPixelMap = nullptr;
+ napi_get_undefined(env, &result);
+
+ ndkPicture_->errCode_ = OH_PictureNative_GetMainPixelmap(ndkPicture_->picture_, &mainPixelMap);
+
+ if (ndkPicture_->errCode_ != IMAGE_SUCCESS || mainPixelMap == nullptr) {
+ H_LOGE("%{public}s OH_PictureNative_GetMainPixelmap failed, errCode: %{public}d.", PROJECT_TAG,
+ ndkPicture_->errCode_);
+ return getJsResult(env, ndkPicture_->errCode_);
+ } else {
+ napi_status status =
+ napi_create_external(env, reinterpret_cast(mainPixelMap), nullptr, nullptr, &result);
+ if (status != napi_ok) {
+ napi_throw_error(env, nullptr, "Failed to create external object");
+ return getJsResult(env, ndkPicture_->errCode_);
+ }
+ H_LOGI("%{public}s OH_PictureNative_GetMainPixelmap success !", PROJECT_TAG);
+ return getJsResult(env, ndkPicture_->errCode_);
+ }
+}
+
+// 获取GainMap辅助图,需要这张Picture包含GainMap辅助图才能成功获取。
+static napi_value GetGainMapPixelMap(napi_env env, napi_callback_info info) {
+ napi_value result;
+ OH_PixelmapNative *gainMapPixelMap = nullptr;
+ ndkPicture_->errCode_ = OH_PictureNative_GetGainmapPixelmap(ndkPicture_->picture_, &gainMapPixelMap);
+ if (ndkPicture_->errCode_ != IMAGE_SUCCESS) {
+ H_LOGE("GetGainMapPixelMap failed, errCode: %{public}d.", ndkPicture_->errCode_);
+ return getJsResult(env, ndkPicture_->errCode_);
+ } else {
+ napi_status status =
+ napi_create_external(env, reinterpret_cast(gainMapPixelMap), nullptr, nullptr, &result);
+ if (status != napi_ok) {
+ napi_throw_error(env, nullptr, "Failed to create external object");
+ return getJsResult(env, ndkPicture_->errCode_);
+ }
+ }
+ H_LOGI("GetGainMapPixelMap success !");
+ return getJsResult(env, ndkPicture_->errCode_);
+}
+
+// 合成hdr图并获取hdr图的pixelmap
+static napi_value GetHdrComposedPixelMap(napi_env env, napi_callback_info info) {
+
+ napi_value result;
+ OH_PixelmapNative *hdrComposedPixelMap = nullptr;
+
+ ndkPicture_->errCode_ = OH_PictureNative_GetHdrComposedPixelmap(ndkPicture_->picture_, &hdrComposedPixelMap);
+
+ if (ndkPicture_->errCode_ != IMAGE_SUCCESS || !hdrComposedPixelMap) {
+ H_LOGE("%{public}s OH_PictureNative_GetHdrComposedPixelmap failed, errCode: %{public}d.", PROJECT_TAG,
+ ndkPicture_->errCode_);
+ return getJsResult(env, ndkPicture_->errCode_);
+ } else {
+ napi_status status =
+ napi_create_external(env, reinterpret_cast(hdrComposedPixelMap), nullptr, nullptr, &result);
+ if (status != napi_ok) {
+ napi_throw_error(env, nullptr, "Failed to create external object");
+ return getJsResult(env, ndkPicture_->errCode_);
+ }
+ H_LOGI("%{public}s OH_PictureNative_GetHdrComposedPixelmap success !", PROJECT_TAG);
+ }
+
+ return getJsResult(env, ndkPicture_->errCode_);
+}
+
+static napi_value CreateAuxiliaryPicture(napi_env env, napi_callback_info info) {
+ napi_value result = nullptr;
+ napi_get_undefined(env, &result);
+ napi_status status;
+
+ size_t argc = 3;
+ napi_value args[3] = {nullptr};
+
+ if (napi_get_cb_info(env, info, &argc, args, nullptr, nullptr) != napi_ok || argc < 3 || args[0] == nullptr ||
+ args[1] == nullptr || args[2] == nullptr) {
+ H_LOGE("%{public}s OH_AuxiliaryPictureNative_Create napi_get_cb_info failed !", PROJECT_TAG);
+ return getJsResult(env, IMAGE_BAD_PARAMETER);
+ }
+
+ void *data0;
+ size_t dataLength = 10;
+ status = napi_get_arraybuffer_info(env, args[0], &data0, &dataLength);
+ IMG_NAPI_CHECK_RET_D(IMG_IS_OK(status), nullptr, H_LOGE("Fail to get auxiliary picture buffer"));
+ uint8_t *data = reinterpret_cast(data0);
+
+ Image_Size *size;
+ napi_value tempValue = nullptr;
+ napi_value tempValue2 = nullptr;
+ IMG_IS_OK(napi_get_named_property(env, args[1], "width", &tempValue));
+ IMG_IS_OK(napi_get_value_uint32(env, tempValue, &size->width));
+ IMG_IS_OK(napi_get_named_property(env, args[1], "height", &tempValue2));
+ IMG_IS_OK(napi_get_value_uint32(env, tempValue2, &size->height));
+
+ int32_t value = 0; // auxType是指向了这个变量的指针
+ int32_t *auxType = &value;
+ status = napi_get_value_int32(env, args[2], auxType);
+ if (*auxType >= static_cast(Image_AuxiliaryPictureType::AUXILIARY_PICTURE_TYPE_GAINMAP) &&
+ *auxType <= static_cast(Image_AuxiliaryPictureType::AUXILIARY_PICTURE_TYPE_FRAGMENT_MAP)) {
+ H_LOGI("%{public}s OH_AuxiliaryPictureNative_Create type: %{public}d.", PROJECT_TAG, *auxType);
+ } else {
+ H_LOGI("%{public}s OH_AuxiliaryPictureNative_Create type is set GAINMAP: %{public}d.", PROJECT_TAG, *auxType);
+ *auxType = static_cast(Image_AuxiliaryPictureType::AUXILIARY_PICTURE_TYPE_GAINMAP);
+ }
+ Image_AuxiliaryPictureType *type = reinterpret_cast(auxType);
+
+ ndkPicture_->errCode_ =
+ OH_AuxiliaryPictureNative_Create(data, dataLength, size, *type, &ndkPicture_->auxiliaryPicture_);
+
+ if (ndkPicture_->errCode_ != IMAGE_SUCCESS || !ndkPicture_->auxiliaryPicture_) {
+ H_LOGE("%{public}s OH_AuxiliaryPictureNative_Create failed, errCode: %{public}d.", PROJECT_TAG,
+ ndkPicture_->errCode_);
+ return getJsResult(env, ndkPicture_->errCode_);
+ } else {
+ napi_status status = napi_create_external(env, reinterpret_cast(ndkPicture_->auxiliaryPicture_),
+ nullptr, nullptr, &result);
+ if (status != napi_ok) {
+ napi_throw_error(env, nullptr, "Failed to create external object");
+ return getJsResult(env, ndkPicture_->errCode_);
+ }
+ H_LOGI("%{public}s OH_AuxiliaryPictureNative_Create success !", PROJECT_TAG);
+ }
+
+ return getJsResult(env, ndkPicture_->errCode_);
+}
+
+static napi_value GetAuxType(napi_env env, napi_callback_info info) {
+ Image_AuxiliaryPictureType type;
+ ndkPicture_->errCode_ = OH_AuxiliaryPictureNative_GetType(ndkPicture_->auxiliaryPicture_, &type);
+
+ if (ndkPicture_->errCode_ != IMAGE_SUCCESS) {
+ H_LOGE("%{public}s OH_AuxiliaryPictureNative_GetType failed, errCode: %{public}d.", PROJECT_TAG,
+ ndkPicture_->errCode_);
+ return getJsResult(env, ndkPicture_->errCode_);
+ } else {
+ H_LOGI("%{public}s OH_AuxiliaryPictureNative_GetType success !", PROJECT_TAG);
+ }
+
+ return getJsResult(env, ndkPicture_->errCode_);
+}
+
+static napi_value SetAuxiliaryPicture(napi_env env, napi_callback_info info) {
+ napi_status status;
+ size_t argc = 1;
+ napi_value args[1] = {nullptr};
+
+ if (napi_get_cb_info(env, info, &argc, args, nullptr, nullptr) != napi_ok || argc < 1 || args[0] == nullptr) {
+ H_LOGE("%{public}s CreatePicture_ napi_get_cb_info failed !", PROJECT_TAG);
+ return getJsResult(env, IMAGE_BAD_PARAMETER);
+ }
+
+ int32_t value = 0; // 假设 auxType 指向了这个变量的地址
+ int32_t *auxType = &value;
+ status = napi_get_value_int32(env, args[0], auxType);
+ if (*auxType >= static_cast(Image_AuxiliaryPictureType::AUXILIARY_PICTURE_TYPE_GAINMAP) &&
+ *auxType <= static_cast(Image_AuxiliaryPictureType::AUXILIARY_PICTURE_TYPE_FRAGMENT_MAP)) {
+ H_LOGI("%{public}s OH_AuxiliaryPictureNative_Create type: %{public}d.", PROJECT_TAG, *auxType);
+ } else {
+ *auxType = static_cast(Image_AuxiliaryPictureType::AUXILIARY_PICTURE_TYPE_GAINMAP);
+ H_LOGI("%{public}s OH_AuxiliaryPictureNative_Create type is set GAINMAP: %{public}d.", PROJECT_TAG, *auxType);
+ }
+ Image_AuxiliaryPictureType *type = reinterpret_cast(auxType);
+
+ if (ndkPicture_->auxiliaryPicture_ == nullptr) {
+ H_LOGE("%{public}s OH_PictureNative_SetAuxiliaryPicture is nullptr", PROJECT_TAG);
+ return getJsResult(env, IMAGE_BAD_PARAMETER);
+ }
+
+ ndkPicture_->errCode_ =
+ OH_PictureNative_SetAuxiliaryPicture(ndkPicture_->picture_, *type, ndkPicture_->auxiliaryPicture_);
+ if (ndkPicture_->errCode_ != IMAGE_SUCCESS) {
+ H_LOGE("%{public}s OH_PictureNative_SetAuxiliaryPicture failed, errCode: %{public}d.", PROJECT_TAG,
+ ndkPicture_->errCode_);
+ return getJsResult(env, ndkPicture_->errCode_);
+ } else {
+ H_LOGI("%{public}s OH_PictureNative_SetAuxiliaryPicture success !", PROJECT_TAG);
+ }
+
+ return getJsResult(env, ndkPicture_->errCode_);
+}
+
+static napi_value GetAuxiliaryPicture(napi_env env, napi_callback_info info) {
+ napi_value result = nullptr;
+ napi_get_undefined(env, &result);
+ napi_status status;
+ size_t argc = 1;
+ napi_value args[1] = {nullptr};
+
+ if (napi_get_cb_info(env, info, &argc, args, nullptr, nullptr) != napi_ok || argc < 1 || args[0] == nullptr) {
+ H_LOGE("%{public}s CreatePicture_ napi_get_cb_info failed !", PROJECT_TAG);
+ return getJsResult(env, IMAGE_BAD_PARAMETER);
+ }
+
+ int32_t value = 0; // 假设 auxType 指向了这个变量的地址
+ int32_t *auxType = &value;
+ status = napi_get_value_int32(env, args[0], auxType);
+ if (*auxType >= static_cast(Image_AuxiliaryPictureType::AUXILIARY_PICTURE_TYPE_GAINMAP) &&
+ *auxType <= static_cast(Image_AuxiliaryPictureType::AUXILIARY_PICTURE_TYPE_FRAGMENT_MAP)) {
+ H_LOGI("%{public}s OH_AuxiliaryPictureNative_Create type: %{public}d.", PROJECT_TAG, *auxType);
+ } else {
+ *auxType = static_cast(Image_AuxiliaryPictureType::AUXILIARY_PICTURE_TYPE_GAINMAP);
+ H_LOGI("%{public}s OH_AuxiliaryPictureNative_Create type is set GAINMAP: %{public}d.", PROJECT_TAG, *auxType);
+ }
+ Image_AuxiliaryPictureType *type = reinterpret_cast(auxType);
+
+ ndkPicture_->errCode_ =
+ OH_PictureNative_GetAuxiliaryPicture(ndkPicture_->picture_, *type, &ndkPicture_->auxiliaryPicture_);
+ if (ndkPicture_->errCode_ != IMAGE_SUCCESS) {
+ H_LOGE("%{public}s OH_PictureNative_GetAuxiliaryPicture failed, errCode: %{public}d.", PROJECT_TAG,
+ ndkPicture_->errCode_);
+ return getJsResult(env, ndkPicture_->errCode_);
+ } else {
+ napi_status status = napi_create_external(env, reinterpret_cast(ndkPicture_->auxiliaryPicture_),
+ nullptr, nullptr, &result);
+ if (status != napi_ok) {
+ napi_throw_error(env, nullptr, "Failed to create external object");
+ return getJsResult(env, ndkPicture_->errCode_);
+ }
+ H_LOGI("%{public}s OH_PictureNative_GetAuxiliaryPicture success !", PROJECT_TAG);
+ }
+
+ return getJsResult(env, ndkPicture_->errCode_);
+}
+
+// 将Picture编码到缓冲区
+static napi_value PackToData(napi_env env, napi_callback_info info) {
+ napi_value result = nullptr;
+ size_t outDataSize = 10000 * 10000;
+ uint8_t *outData = new uint8_t[outDataSize];
+
+ if (ndkPicture_->packerOptions_ == nullptr) {
+ ndkPicture_->errCode_ = OH_PackingOptions_Create(&ndkPicture_->packerOptions_);
+ }
+ if (ndkPicture_->imagePacker_ == nullptr) {
+ ndkPicture_->errCode_ = OH_ImagePackerNative_Create(&ndkPicture_->imagePacker_);
+ }
+ Image_MimeType format;
+ format.size = 10;
+ format.data = const_cast("image/jpeg");
+ OH_PackingOptions_SetMimeType(ndkPicture_->packerOptions_, &format);
+ ndkPicture_->errCode_ = OH_ImagePackerNative_PackToDataFromPicture(
+ ndkPicture_->imagePacker_, ndkPicture_->packerOptions_, ndkPicture_->picture_, outData, &outDataSize);
+ if (ndkPicture_->errCode_ != IMAGE_SUCCESS) {
+ H_LOGE("%{public}s OH_ImagePackerNative_PackToDataFromPicture failed, errCode: %{public}d.", PROJECT_TAG,
+ ndkPicture_->errCode_);
+ delete [] outData;
+ return getJsResult(env, ndkPicture_->errCode_);
+ } else {
+ napi_status status = napi_create_external(env, reinterpret_cast(outData), nullptr, nullptr, &result);
+ if (status != napi_ok) {
+ napi_throw_error(env, nullptr, "Failed to create external object");
+ delete [] outData;
+ return getJsResult(env, ndkPicture_->errCode_);
+ }
+ H_LOGI("%{public}s OH_ImagePackerNative_PackToDataFromPicture success !", PROJECT_TAG);
+ }
+ delete [] outData;
+ return getJsResult(env, ndkPicture_->errCode_);
+};
+
+// 将Picture编码到图片文件
+static napi_value PackToFile(napi_env env, napi_callback_info info) {
+ napi_value result;
+ size_t argc = 1;
+ napi_value args[1] = {nullptr};
+ if (napi_get_cb_info(env, info, &argc, args, nullptr, nullptr) != napi_ok) {
+ napi_create_int32(env, -1, &result);
+ H_LOGE("%{public}s napi_get_cb_info failed !", PROJECT_TAG);
+ return getJsResult(env, ndkPicture_->errCode_);
+ }
+ uint32_t fd = 0;
+ napi_get_value_uint32(env, args[0], &fd);
+
+ if (ndkPicture_->packerOptions_ == nullptr) {
+ ndkPicture_->errCode_ = OH_PackingOptions_Create(&ndkPicture_->packerOptions_);
+ }
+ if (ndkPicture_->imagePacker_ == nullptr) {
+ ndkPicture_->errCode_ = OH_ImagePackerNative_Create(&ndkPicture_->imagePacker_);
+ }
+ Image_MimeType format;
+ format.size = 10;
+ format.data = const_cast("image/jpeg");
+ OH_PackingOptions_SetMimeType(ndkPicture_->packerOptions_, &format);
+ ndkPicture_->errCode_ = OH_ImagePackerNative_PackToFileFromPicture(
+ ndkPicture_->imagePacker_, ndkPicture_->packerOptions_, ndkPicture_->picture_, fd);
+ if (ndkPicture_->errCode_ != IMAGE_SUCCESS) {
+ H_LOGE("%{public}s OH_ImagePackerNative_PackToFileFromPicture failed, errCode: %{public}d.", PROJECT_TAG,
+ ndkPicture_->errCode_);
+
+ return getJsResult(env, ndkPicture_->errCode_);
+ } else {
+ H_LOGI("%{public}s OH_ImagePackerNative_PackToFileFromPicture success !", PROJECT_TAG);
+ }
+
+ return getJsResult(env, ndkPicture_->errCode_);
+}
+
+static napi_value ReleasePicture(napi_env env, napi_callback_info info) {
+ ndkPicture_->errCode_ = OH_PictureNative_Release(ndkPicture_->picture_);
+ ndkPicture_->picture_ = nullptr;
+ if (ndkPicture_->errCode_ != IMAGE_SUCCESS) {
+ H_LOGE("%{public}s OH_PictureNative_Release failed, errCode: %{public}d.", PROJECT_TAG, ndkPicture_->errCode_);
+ return getJsResult(env, ndkPicture_->errCode_);
+ } else {
+ H_LOGI("%{public}s OH_PictureNative_Release success !", PROJECT_TAG);
+ }
+
+ return getJsResult(env, ndkPicture_->errCode_);
+}
+
+EXTERN_C_START
+static napi_value Init(napi_env env, napi_value exports) {
+ napi_property_descriptor desc[] = {
+ {"CreatePicture", nullptr, CreatePicture, nullptr, nullptr, nullptr, napi_default, nullptr},
+ {"GetMainPixelMap", nullptr, GetMainPixelMap, nullptr, nullptr, nullptr, napi_default, nullptr},
+ {"CreatePictureByImageSource", nullptr, CreatePictureByImageSource, nullptr, nullptr, nullptr, napi_default,
+ nullptr},
+ {"PackToData", nullptr, PackToData, nullptr, nullptr, nullptr, napi_default, nullptr},
+ {"PackToFile", nullptr, PackToFile, nullptr, nullptr, nullptr, napi_default, nullptr},
+ {"ReleasePicture", nullptr, ReleasePicture, nullptr, nullptr, nullptr, napi_default, nullptr},
+ };
+ napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
+ return exports;
+}
+EXTERN_C_END
+
+static napi_module demoModule = {
+ .nm_version = 1,
+ .nm_flags = 0,
+ .nm_filename = nullptr,
+ .nm_register_func = Init,
+ .nm_modname = "entry",
+ .nm_priv = ((void *)0),
+ .reserved = {0},
+};
+
+extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); }
\ No newline at end of file
diff --git a/code/DocsSample/Media/Image/NdkPicture/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/cpp/types/libentry/Index.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..e6554ceac274a0f9426ae83ae0b54d2745b91f3a
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/cpp/types/libentry/Index.d.ts
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2025 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.
+ */
+import { image } from "@kit.ImageKit";
+
+declare namespace ndk_picture {
+ export const CreatePicture: (path: string) => number;
+
+ export const CreatePictureByImageSource: (path: string) => number;
+
+ export const GetMainPixelMap: () => number;
+
+ export const PackToData: () => number;
+
+ export const PackToFile: (fd: number) => number;
+
+ export const ReleasePicture: () => number;
+}
+
+export default ndk_picture;
\ No newline at end of file
diff --git a/code/DocsSample/Media/Image/NdkPicture/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/cpp/types/libentry/oh-package.json5
new file mode 100644
index 0000000000000000000000000000000000000000..77052c679533e45a066030a9fc21cdbf9cbcf995
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/cpp/types/libentry/oh-package.json5
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2025 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.
+ */
+{
+ "name": "libentry.so",
+ "types": "./Index.d.ts",
+ "version": "1.0.0",
+ "description": "Please describe the basic information."
+}
\ No newline at end of file
diff --git a/code/DocsSample/Media/Image/NdkPicture/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/ets/entryability/EntryAbility.ets
new file mode 100644
index 0000000000000000000000000000000000000000..843c7f0c1f7b9a460e3dbbd2689e5b34016027d1
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/ets/entryability/EntryAbility.ets
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2025 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.
+ */
+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/code/DocsSample/Media/Image/NdkPicture/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets
new file mode 100644
index 0000000000000000000000000000000000000000..4ce6449f0e91914e73d4502c9f2e8e9a395ea4b1
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2025 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.
+ */
+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/code/DocsSample/Media/Image/NdkPicture/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/ets/pages/Index.ets
new file mode 100644
index 0000000000000000000000000000000000000000..06fc61fa7bb153b8a8cceeedc13a7e9cb1644b6d
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/ets/pages/Index.ets
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2025 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.
+ */
+import image from '@ohos.multimedia.image';
+import { myButton } from '../utils/MyButton'
+import { PictureFunctions } from '../utils/PicutreFunctions'
+
+@Entry
+@Component
+struct Index {
+ @State message: number = 0;
+ @State picture: image.Picture | null = null;
+ @State returnMessage: string = "No";
+ private test = new PictureFunctions();
+
+ build() {
+ Row() {
+ Column() {
+ List() {
+ ListItem() {
+ myButton({ text: "Create Picture", fun: this.test.createPicture })
+ }
+
+ ListItem() {
+ myButton({ text: "Get MainPixelMap", fun: this.test.getMainPixelMap })
+ }
+
+ ListItem() {
+ myButton({ text: "Pack to Data", fun: this.test.packToData })
+ }
+
+ ListItem() {
+ myButton({ text: "Pack to File", fun: this.test.packToFile })
+ }
+
+ ListItem() {
+ myButton({ text: "Release Picture", fun: this.test.pictureRelease })
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/code/DocsSample/Media/Image/NdkPicture/entry/src/main/ets/utils/Logger.ets b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/ets/utils/Logger.ets
new file mode 100644
index 0000000000000000000000000000000000000000..7c739c2a2b0bb94b9e444ab564ce665d4de8f6e0
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/ets/utils/Logger.ets
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2025 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.
+ */
+
+export class AppLog {
+ constructor(tag: string) {
+ this.tagName = tag
+ }
+ prefix : string = '[Sample_NdkPicture]'
+ tagName: string
+ log = (msg: string) => {
+ console.info(this.prefix + this.tagName + ' ' + msg)
+ }
+ check_result = (msg: string, res: object | number) => {
+ if (typeof res === "object") {
+ this.log(msg + `object result success :${res}`)
+ } else if (typeof res === "number") {
+ if (res == 0) {
+ this.log(msg + `: errorcode result succ: ${res}`)
+ } else {
+ this.log(msg + `: errorcode result failed: ${res}`)
+ }
+ } else {
+ this.log(msg + `unknown result type: ${res}`)
+ }
+ }
+}
\ No newline at end of file
diff --git a/code/DocsSample/Media/Image/NdkPicture/entry/src/main/ets/utils/MyButton.ets b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/ets/utils/MyButton.ets
new file mode 100644
index 0000000000000000000000000000000000000000..b99101268f4fe944c59eb4f90081a644de6ecfaf
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/ets/utils/MyButton.ets
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2025 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.
+ */
+import { AppLog } from '../utils/Logger'
+
+const TAG: string = "DEBUG TEST";
+
+@Component
+export struct myButton {
+ //自定义button 回调函数目前只支持void和无参
+ public logger = new AppLog(TAG);
+ public fun: () => void = () => {
+ };
+ public text = "This is a button";
+ @State returnMessage: string = "No";
+
+ build() {
+ Row() {
+ Column() {
+ Blank().height(40);
+ Button(`${this.text}`)
+ .labelStyle({
+ overflow: TextOverflow.Clip,
+ maxLines: 2,
+ minFontSize: 20,
+ maxFontSize: 20,
+ font: {
+ size: 20,
+ weight: FontWeight.Bolder,
+ family: 'cursive',
+ style: FontStyle.Italic
+ }
+ })
+ .onClick(() => {
+ this.logger.log("\n start->>>>>>>>>>>>>>>>>>>>>>");
+ this.fun();
+ this.logger.log((this.fun.toString()) + "\n end:->>>>>>>>>>>>>>>>>>>>>>");
+ this.returnMessage = "Yes";
+ })
+ Blank().height(40);
+ Divider();
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/code/DocsSample/Media/Image/NdkPicture/entry/src/main/ets/utils/PicutreFunctions.ets b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/ets/utils/PicutreFunctions.ets
new file mode 100644
index 0000000000000000000000000000000000000000..b7f0f97f0c50fef646d33ba2cc68c8d642bbe219
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/ets/utils/PicutreFunctions.ets
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2025 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.
+ */
+import testNapi from 'libentry.so';
+import fs from '@ohos.file.fs'
+import {AppLog } from '../utils/Logger'
+import image from '@ohos.multimedia.image';
+import { BusinessError } from '@kit.BasicServicesKit';
+import { promptAction } from '@kit.ArkUI';
+
+const TAG: string = 'PictureFunctions: '
+export class PictureFunctions {
+ constructor() {
+ }
+
+ private logger = new AppLog(TAG)
+
+ createPicture() {
+ this.logger.log("start createPicture");
+ let context = getContext();
+ let filePath = context.filesDir + "/test.jpg";
+ let ec = testNapi.CreatePicture(filePath);
+ if(ec === 0) {
+ promptAction.showToast({ message: 'Create Picture Success.'});
+ } else {
+ this.logger.log("CreatePicture error is: " + ec);
+ }
+ }
+
+ createPictureByImageSource() {
+ this.logger.log("start createPicture");
+ let context = getContext();
+ let filePath = context.filesDir + "/test.jpg";
+ let ec = testNapi.CreatePictureByImageSource(filePath);
+ if(ec === 0) {
+ promptAction.showToast({ message: 'Create Picture Success.'});
+ } else {
+ this.logger.log("CreatePicture error is: " + ec);
+ }
+ }
+
+ getMainPixelMap() {
+ let ec = testNapi.GetMainPixelMap();
+ this.logger.check_result("GetMainPixelMap", ec);
+ if(ec === 0) {
+ promptAction.showToast({ message: 'getMainPixelMap Success.'});
+ } else {
+ promptAction.showToast({ message: 'getMainPixelMap failed. Please create picture first.'});
+ this.logger.log("getMainPixelMap error is: " + ec);
+ }
+ }
+
+ packToData(): void {
+ let ec = testNapi.PackToData();
+ this.logger.check_result("packToDataFromPicture result is:" , ec);
+ if(ec === 0) {
+ promptAction.showToast({ message: 'packToData Success.'});
+ } else {
+ promptAction.showToast({ message: 'packToData failed. Please create picture first.'});
+ this.logger.log("packToData error is: " + ec);
+ }
+ }
+
+ packToFile(): void {
+ let context = getContext();
+ let filePath = context.filesDir + "/packTest.jpg";
+ let file = fs.openSync(filePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
+ let ec = testNapi.PackToFile(file.fd);
+ this.logger.check_result("packToDataFromPicture result is:" , ec);
+ if(ec === 0) {
+ promptAction.showToast({ message: 'packToFile Success.'});
+ } else {
+ promptAction.showToast({ message: 'packToFile failed. Please create picture first.'});
+ this.logger.log("packToFile error is: " + ec);
+ }
+ }
+
+ pictureRelease() {
+ let ec = testNapi.ReleasePicture();
+ this.logger.check_result("pictureNative_Release done, return is:" , ec);
+ if(ec === 0) {
+ promptAction.showToast({ message: 'pictureRelease Success.'});
+ } else {
+ promptAction.showToast({ message: 'pictureRelease failed. Please create picture first.'});
+ this.logger.log("pictureRelease error is: " + ec);
+ }
+ }
+}
\ No newline at end of file
diff --git a/code/DocsSample/Media/Image/NdkPicture/entry/src/main/module.json5 b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/module.json5
new file mode 100644
index 0000000000000000000000000000000000000000..c75d702e2d350523978ecaf801c22762ce7d40c0
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/module.json5
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2025 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.
+ */
+{
+ "module": {
+ "name": "entry",
+ "type": "entry",
+ "description": "$string:module_desc",
+ "mainElement": "EntryAbility",
+ "deviceTypes": [
+ "default",
+ "tablet"
+ ],
+ "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/code/DocsSample/Media/Image/NdkPicture/entry/src/main/resources/base/element/color.json b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/resources/base/element/color.json
new file mode 100644
index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/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/code/DocsSample/Media/Image/NdkPicture/entry/src/main/resources/base/element/float.json b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/resources/base/element/float.json
new file mode 100644
index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/resources/base/element/float.json
@@ -0,0 +1,8 @@
+{
+ "float": [
+ {
+ "name": "page_text_font_size",
+ "value": "50fp"
+ }
+ ]
+}
diff --git a/code/DocsSample/Media/Image/NdkPicture/entry/src/main/resources/base/element/string.json b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/resources/base/element/string.json
new file mode 100644
index 0000000000000000000000000000000000000000..6b14e1dbad3297c648c76f395769012a3f41c8af
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/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": "NdkPicture"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/code/DocsSample/Media/Image/NdkPicture/entry/src/main/resources/base/media/background.png b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/resources/base/media/background.png
new file mode 100644
index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f
Binary files /dev/null and b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/resources/base/media/background.png differ
diff --git a/code/DocsSample/Media/Image/NdkPicture/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/resources/base/media/foreground.png
new file mode 100644
index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f
Binary files /dev/null and b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/resources/base/media/foreground.png differ
diff --git a/code/DocsSample/Media/Image/NdkPicture/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/resources/base/media/layered_image.json
new file mode 100644
index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/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/code/DocsSample/Media/Image/NdkPicture/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/resources/base/media/startIcon.png
new file mode 100644
index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b
Binary files /dev/null and b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/resources/base/media/startIcon.png differ
diff --git a/code/DocsSample/Media/Image/NdkPicture/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/resources/base/profile/backup_config.json
new file mode 100644
index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/resources/base/profile/backup_config.json
@@ -0,0 +1,3 @@
+{
+ "allowToBackupRestore": true
+}
\ No newline at end of file
diff --git a/code/DocsSample/Media/Image/NdkPicture/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/resources/base/profile/main_pages.json
new file mode 100644
index 0000000000000000000000000000000000000000..55c3f007f87b7ce5206d325f968cc56f2f79441f
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/resources/base/profile/main_pages.json
@@ -0,0 +1,5 @@
+{
+ "src": [
+ "pages/Index"
+ ]
+}
\ No newline at end of file
diff --git a/code/DocsSample/Media/Image/NdkPicture/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/resources/dark/element/color.json
new file mode 100644
index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/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/code/DocsSample/Media/Image/NdkPicture/entry/src/main/resources/rawfile/test.jpg b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/resources/rawfile/test.jpg
new file mode 100644
index 0000000000000000000000000000000000000000..28eea137afa5584f35736d3b13423a8a9816df2a
Binary files /dev/null and b/code/DocsSample/Media/Image/NdkPicture/entry/src/main/resources/rawfile/test.jpg differ
diff --git a/code/DocsSample/Media/Image/NdkPicture/entry/src/mock/Libentry.mock.ets b/code/DocsSample/Media/Image/NdkPicture/entry/src/mock/Libentry.mock.ets
new file mode 100644
index 0000000000000000000000000000000000000000..82fa70b5693ddab96d237d2d17d943d866b61465
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/entry/src/mock/Libentry.mock.ets
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2025 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.
+ */
+const NativeMock: Record = {
+ 'add': (a: number, b: number) => {
+ return a + b;
+ },
+};
+
+export default NativeMock;
\ No newline at end of file
diff --git a/code/DocsSample/Media/Image/NdkPicture/entry/src/mock/mock-config.json5 b/code/DocsSample/Media/Image/NdkPicture/entry/src/mock/mock-config.json5
new file mode 100644
index 0000000000000000000000000000000000000000..98b0ae79f0090e1fc381d54c959fb32c9f7563f4
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/entry/src/mock/mock-config.json5
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2025 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.
+ */
+{
+ "libentry.so": {
+ "source": "src/mock/Libentry.mock.ets"
+ }
+}
\ No newline at end of file
diff --git a/code/DocsSample/Media/Image/NdkPicture/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Media/Image/NdkPicture/entry/src/ohosTest/ets/test/Ability.test.ets
new file mode 100644
index 0000000000000000000000000000000000000000..987b1a582262f0c046c8296bed24b9947579caac
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/entry/src/ohosTest/ets/test/Ability.test.ets
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2025 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.
+ */
+import { hilog } from '@kit.PerformanceAnalysisKit';
+import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
+import { Driver, ON } from '@ohos.UiTest';
+import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
+
+export default function abilityTest() {
+ const TAG: string = '[Sample_NdkPicture]';
+ const DOMAIN = 0xF811;
+ const BUNDLE = 'NdkPicture_';
+ const DELAY_TIME = 1000;
+ const driver = Driver.create();
+ const abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
+ const bundleName = AbilityDelegatorRegistry.getArguments().bundleName;
+ 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('StartAbility_001', 0, async (done: Function) => {
+ console.info(TAG, 'StartAbility_001 begin');
+
+ try {
+ await abilityDelegator.startAbility({
+ bundleName: bundleName,
+ abilityName: 'EntryAbility'
+ });
+ } catch (exception) {
+ hilog.error(DOMAIN, TAG, `StartAbility_001 exception = ${JSON.stringify(exception)}`);
+ expect().assertFail();
+ }
+ await driver.delayMs(3000);
+ done();
+ console.info(TAG, 'StartAbility_001 end');
+ })
+ /**
+ * 解码得到Picture
+ */
+ it(BUNDLE + 'CreatePicture_001', 0, async (done: Function) => {
+ hilog.info(DOMAIN, TAG, BUNDLE + 'CreatePicture_001 begin');
+ await driver.delayMs(DELAY_TIME);
+ // 点击 Create Picture 按钮
+ await driver.assertComponentExist(ON.text("Create Picture"));
+ let btn = await driver.findComponent(ON.text("Create Picture"));
+ await btn.click();
+ await driver.delayMs(DELAY_TIME);
+ hilog.info(DOMAIN, TAG, BUNDLE + 'CreatePicture_001 end');
+ done();
+ })
+ /**
+ * 获取主图
+ */
+ it(BUNDLE + 'GetMainPixelMap_001', 0, async (done: Function) => {
+ hilog.info(DOMAIN, TAG, BUNDLE + 'GetMainPixelMap_001 begin');
+ await driver.delayMs(DELAY_TIME);
+ // 点击 Get MainPixelMap 按钮
+ await driver.assertComponentExist(ON.text("Get MainPixelMap"));
+ let btn = await driver.findComponent(ON.text("Get MainPixelMap"));
+ await btn.click();
+ await driver.delayMs(DELAY_TIME);
+ hilog.info(DOMAIN, TAG, BUNDLE + 'GetMainPixelMap_001 end');
+ done();
+ })
+ /**
+ * 将Picture编码到缓冲区
+ */
+ it(BUNDLE + 'PackToData_001', 0, async (done: Function) => {
+ hilog.info(DOMAIN, TAG, BUNDLE + 'PackToData_001 begin');
+ await driver.delayMs(DELAY_TIME);
+ // 点击 Pack to Data 按钮
+ await driver.assertComponentExist(ON.text("Pack to Data"));
+ let btn = await driver.findComponent(ON.text("Pack to Data"));
+ await btn.click();
+ await driver.delayMs(DELAY_TIME);
+ hilog.info(DOMAIN, TAG, BUNDLE + 'PackToData_001 end');
+ done();
+ })
+ /**
+ * 将Picture编码到图片文件
+ */
+ it(BUNDLE + 'PackToFile_001', 0, async (done: Function) => {
+ hilog.info(DOMAIN, TAG, BUNDLE + 'PackToFile_001 begin');
+ await driver.delayMs(DELAY_TIME);
+ // 点击 Pack to File 按钮
+ await driver.assertComponentExist(ON.text("Pack to File"));
+ let btn = await driver.findComponent(ON.text("Pack to File"));
+ await btn.click();
+ await driver.delayMs(DELAY_TIME);
+ hilog.info(DOMAIN, TAG, BUNDLE + 'PackToFile_001 end');
+ done();
+ })
+ /**
+ * 释放Picture
+ */
+ it(BUNDLE + 'ReleasePicture_001', 0, async (done: Function) => {
+ hilog.info(DOMAIN, TAG, BUNDLE + 'ReleasePicture_001 begin');
+ await driver.delayMs(DELAY_TIME);
+ // 点击 Release Picture 按钮
+ await driver.assertComponentExist(ON.text("Release Picture"));
+ let btn = await driver.findComponent(ON.text("Release Picture"));
+ await btn.click();
+ await driver.delayMs(DELAY_TIME);
+ hilog.info(DOMAIN, TAG, BUNDLE + 'ReleasePicture_001 end');
+ done();
+ })
+ })
+}
\ No newline at end of file
diff --git a/code/DocsSample/Media/Image/NdkPicture/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Media/Image/NdkPicture/entry/src/ohosTest/ets/test/List.test.ets
new file mode 100644
index 0000000000000000000000000000000000000000..c64e0b06938d246ce044186d4b2d02b500a89e14
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/entry/src/ohosTest/ets/test/List.test.ets
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2025 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.
+ */
+import abilityTest from './Ability.test';
+
+export default function testsuite() {
+ abilityTest();
+}
\ No newline at end of file
diff --git a/code/DocsSample/Media/Image/NdkPicture/entry/src/ohosTest/module.json5 b/code/DocsSample/Media/Image/NdkPicture/entry/src/ohosTest/module.json5
new file mode 100644
index 0000000000000000000000000000000000000000..69026872775eebd0844900b225c411959ae5608b
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/entry/src/ohosTest/module.json5
@@ -0,0 +1,12 @@
+{
+ "module": {
+ "name": "entry_test",
+ "type": "feature",
+ "deviceTypes": [
+ "default",
+ "tablet"
+ ],
+ "deliveryWithInstall": true,
+ "installationFree": false
+ }
+}
diff --git a/code/DocsSample/Media/Image/NdkPicture/entry/src/test/List.test.ets b/code/DocsSample/Media/Image/NdkPicture/entry/src/test/List.test.ets
new file mode 100644
index 0000000000000000000000000000000000000000..bb5b5c3731e283dd507c847560ee59bde477bbc7
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/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/code/DocsSample/Media/Image/NdkPicture/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Media/Image/NdkPicture/entry/src/test/LocalUnit.test.ets
new file mode 100644
index 0000000000000000000000000000000000000000..165fc1615ee8618b4cb6a622f144a9a707eee99f
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/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/code/DocsSample/Media/Image/NdkPicture/hvigor/hvigor-config.json5 b/code/DocsSample/Media/Image/NdkPicture/hvigor/hvigor-config.json5
new file mode 100644
index 0000000000000000000000000000000000000000..15688394471007faea3f8215ad9e367b25f428b6
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/hvigor/hvigor-config.json5
@@ -0,0 +1,22 @@
+{
+ "modelVersion": "5.0.3",
+ "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/code/DocsSample/Media/Image/NdkPicture/hvigorfile.ts b/code/DocsSample/Media/Image/NdkPicture/hvigorfile.ts
new file mode 100644
index 0000000000000000000000000000000000000000..f3cb9f1a87a81687554a76283af8df27d8bda775
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/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/code/DocsSample/Media/Image/NdkPicture/oh-package.json5 b/code/DocsSample/Media/Image/NdkPicture/oh-package.json5
new file mode 100644
index 0000000000000000000000000000000000000000..c44d132b0b0fc4c38d7050a308f0d7f4aeb0653c
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/oh-package.json5
@@ -0,0 +1,10 @@
+{
+ "modelVersion": "5.0.3",
+ "description": "Please describe the basic information.",
+ "dependencies": {
+ },
+ "devDependencies": {
+ "@ohos/hypium": "1.0.21",
+ "@ohos/hamock": "1.0.0"
+ }
+}
diff --git a/code/DocsSample/Media/Image/NdkPicture/ohosTest.md b/code/DocsSample/Media/Image/NdkPicture/ohosTest.md
new file mode 100644
index 0000000000000000000000000000000000000000..c3b2dc3594da5dc6d15a3fc73a32db7d7a4e7d73
--- /dev/null
+++ b/code/DocsSample/Media/Image/NdkPicture/ohosTest.md
@@ -0,0 +1,12 @@
+# NdkPicture测试用例归档
+
+## 用例表
+
+| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 |
+|------------------------|--------------|-----------------------------|-----------------------------------|----------|----------|
+| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass |
+| 图片解码功能 | 进入主界面 | 点击 Create Picture 按钮 | 弹窗通知 createPicture Success. | 是 | Pass |
+| 获取主图功能 | 进入主界面 | 点击位图操作按钮 | 弹窗通知 getMainPixelMap Success.| 是 | Pass |
+| 图片编码到缓冲区功能 | 进入主界面 | 点击 Pack To Data 按钮 | 弹窗通知 packToData Success. | 是 | Pass |
+| 图片编码到文件功能 | 进入主界面 | 点击 Pack To File 按钮 | 弹窗通知 packToFile Success. | 是 | Pass |
+| 释放 Picture 功能 | 进入主界面 | 点击 Realease Picture 按钮 | 弹窗通知 pictureRelease Success | 是 | Pass |
\ No newline at end of file
diff --git a/code/DocsSample/Media/Image/NdkPicture/screenshots/NdkPictureUI.png b/code/DocsSample/Media/Image/NdkPicture/screenshots/NdkPictureUI.png
new file mode 100644
index 0000000000000000000000000000000000000000..dd36e2e22067ad41f824305075d737f5900c0bc3
Binary files /dev/null and b/code/DocsSample/Media/Image/NdkPicture/screenshots/NdkPictureUI.png differ