提交 ae7a64a7 编写于 作者: G Gloria

Update docs against 19539+19829+19463+19784+19539

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 4692348c
# Image Transformation (Native)
You will learn how to use native image APIs to process images, including cropping, rotating, scaling, flipping, translating, and opacity setting.
You will learn how to use native image APIs to process images.
## How to Develop
......@@ -22,9 +22,9 @@ Open the **src/main/cpp/hello.cpp** file and add the following API mappings to t
static napi_value Init(napi_env env, napi_value exports)
{
napi_property_descriptor desc[] = {
{ "createPixelMap", nullptr, CreatePixelMap, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "createAlphaPixelMap", nullptr, CreateAlphaPixelMap, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "transform", nullptr, Transform, nullptr, nullptr, nullptr, napi_default, nullptr }
{ "testGetImageInfo", nullptr, TestGetImageInfo, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "testAccessPixels", nullptr, TestAccessPixels, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "testUnAccessPixels", nullptr, TestUnAccessPixels, nullptr, nullptr, nullptr, napi_default, nullptr },
};
napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
......@@ -40,159 +40,56 @@ For details about the APIs, see [Image API Reference](../reference/native-apis/i
Obtain the JS resource object from the **hello.cpp** file and convert it to a native resource object. Then you can call native APIs. The sample code is as follows:
1. Create a **PixelMap** object based on a pixel array.
```c++
// Create a PixelMap object.
napi_value CreatePixelMap(napi_env env, napi_callback_info info)
1. Obtain the **PixelMap** information and store the information to the **OhosPixelMapInfo** struct.
```c++
static napi_value TestGetImageInfo(napi_env env, napi_callback_info info)
{
napi_value udfVar = nullptr;
napi_value thisVar = nullptr;
napi_value argValue[2] = {0};
size_t argCount = 2;
napi_value result = nullptr;
napi_get_undefined(env, &result);
void* buffer = nullptr;
size_t bufferSize = 0;
struct OhosPixelMapCreateOps createOps;
napi_value pixelmap = nullptr;
napi_value thisVar = nullptr;
napi_value argValue[1] = {0};
size_t argCount = 1;
napi_get_undefined(env, &udfVar);
napi_get_cb_info(env, info, &argCount, argValue, &thisVar, nullptr);
if (napi_get_arraybuffer_info(env, argValue[0], &buffer, &bufferSize) != napi_ok ||
buffer == nullptr || bufferSize == 0) {
return udfVar;
}
createOps.width = 4;
createOps.height = 6;
createOps.pixelFormat = 4;
createOps.alphaType = 0;
int32_t res = OH_PixelMap_CreatePixelMap(env, createOps, (uint8_t *)buffer, bufferSize, &pixelmap);
if (res != OHOS_IMAGE_RESULT_SUCCESS || pixelmap == nullptr) {
return udfVar;
}
return pixelmap;
OHOS::Media::OhosPixelMapInfo pixelMapInfo;
OHOS::Media::OH_GetImageInfo(env, argValue[0], &pixelMapInfo);
return result;
}
// Create a PixelMap object that contains only the alpha channel.
napi_value CreateAlphaPixelMap(napi_env env, napi_callback_info info)
```
2. Obtain the memory address of a **PixelMap** object and lock the memory.
```c++
static napi_value TestAccessPixels(napi_env env, napi_callback_info info)
{
napi_value udfVar = nullptr;
napi_value result = nullptr;
napi_get_undefined(env, &result);
napi_value thisVar = nullptr;
napi_value argValue[1] = {0};
size_t argCount = 1;
napi_value alphaPixelmap = nullptr;
napi_get_undefined(env, &udfVar);
napi_get_cb_info(env, info, &argCount, argValue, &thisVar, nullptr);
if (napi_get_cb_info(env, info, &argCount, argValue, &thisVar, nullptr) != napi_ok ||
argCount < 1 || argValue[0] == nullptr) {
return udfVar;
}
int32_t res = OH_PixelMap_CreateAlphaPixelMap(env, argValue[0], &alphaPixelmap);
if (res != OHOS_IMAGE_RESULT_SUCCESS || alphaPixelmap == nullptr) {
return udfVar;
}
return alphaPixelmap;
void* addrPtr = nullptr;
OHOS::Media::OH_AccessPixels(env, argValue[0], &addrPtr);
return result;
}
```
2. Perform image transformation. For details about the operation, read the comments in the sample code below.
3. Unlock the memory of the **PixelMap** object.
```c++
napi_value Transform(napi_env env, napi_callback_info info)
static napi_value TestUnAccessPixels(napi_env env, napi_callback_info info)
{
napi_value thisVar = nullptr;
napi_value argValue[1] = {0};
size_t argCount = 1;
if (napi_get_cb_info(env, info, &argCount, argValue, &thisVar, nullptr) != napi_ok ||
argCount < 1 || argValue[0] == nullptr) {
return nullptr;
}
napi_value result = nullptr;
napi_get_undefined(env, &result);
NativePixelMap* native = OH_PixelMap_InitNativePixelMap(env, argValue[0]);
if (native == nullptr) {
return result;
}
napi_value thisVar = nullptr;
napi_value argValue[1] = {0};
size_t argCount = 1;
// Obtain image information.
struct OhosPixelMapInfo pixelmapInfo;
OH_PixelMap_GetImageInfo(native, &pixelmapInfo);
// Obtain the number of bytes per row of the PixelMap object.
int32_t rowBytes;
OH_PixelMap_GetBytesNumberPerRow(native, &rowBytes);
// Check whether the PixelMap object is editable.
int32_t editable = 0;
OH_PixelMap_GetIsEditable(native, &editable);
// Check whether the PixelMap object supports alpha channels.
int32_t supportAlpha = 0;
OH_PixelMap_IsSupportAlpha(native, &supportAlpha);
// Set an alpha channel for the PixelMap object.
int32_t alphaAble = 0;
OH_PixelMap_SetAlphaAble(native, alphaAble);
// Obtain the pixel density of the PixelMap object.
int32_t densityG;
OH_PixelMap_GetDensity(native, &densityG);
// Set the pixel density for the PixelMap object.
int32_t densityS = 100;
OH_PixelMap_SetDensity(native, densityS);
// Set the opacity for the PixelMap object.
float opacity = 0.5;
OH_PixelMap_SetOpacity(native, opacity);
// Scale the image.
// scaleX: The width of the image after scaling is 0.5 of the original width.
// scaleY: The height of the image after scaling is 0.5 of the original height.
float scaleX = 0.5;
float scaleY = 0.5;
OH_PixelMap_Scale(native, scaleX, scaleY);
// Translate the image.
// translateX: Translate the image by 50 units downwards.
// translateY: Translate the image by 50 units rightwards.
float translateX = 50;
float translateY = 50;
OH_PixelMap_Translate(native, translateX, translateY);
// Rate the image clockwise by 90°.
float angle = 90;
OH_PixelMap_Rotate(native, angle);
// Flip the image.
// flipX: whether to flip the image horizontally. The value 1 means to flip the image and 0 means the opposite.
// flipY: whether to flip the image vertically. The value 1 means to flip the image and 0 means the opposite.
int32_t flipX = 0;
int32_t flipY = 1;
OH_PixelMap_Flip(native, flipX, flipY);
// Crop the image.
// cropX: x-axis coordinate of the start point for cropping (0).
// cropY: y-axis coordinate of the start point for cropping (0).
// cropH: height after cropping (10), cropping from top to bottom.
// cropW: width after cropping (10), cropping from left to right.
int32_t cropX = 1;
int32_t cropY = 1;
int32_t cropW = 10;
int32_t cropH = 10;
OH_PixelMap_Crop(native, cropX, cropY, cropW, cropH);
uint8_t* pixelAddr = nullptr;
// Obtain the memory address of the PixelMap object and lock the memory.
OH_PixelMap_AccessPixels(native, &pixelAddr);
// Unlock the memory of the PixelMap object.
OH_PixelMap_UnAccessPixels(native);
napi_get_cb_info(env, info, &argCount, argValue, &thisVar, nullptr);
OHOS::Media::OH_UnAccessPixels(env, argValue[0]);
return result;
}
```
......@@ -205,37 +102,41 @@ Obtain the JS resource object from the **hello.cpp** file and convert it to a na
```js
import testNapi from 'libentry.so'
import image from '@ohos.multimedia.image'
import image from '@ohos.multimedia.image';
@Entry
@Component
struct Index {
@State _pixelMap: image.PixelMap = undefined;
build() {
Row() {
Column() {
Button("PixelMap")
.width(100)
.height(100)
.onClick(() => {
const color = new ArrayBuffer(96);
var bufferArr = new Uint8Array(color);
for (var i = 0; i < bufferArr.length; i++) {
bufferArr[i] = 0x80;
}
this._pixelMap = testNapi.createPixelMap(color);
testNapi.transform(this._pixelMap);
@State message: string = 'IMAGE'
@State _PixelMap: image.PixelMap = undefined
build() {
Row() {
Column() {
Button(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
.onClick(() => {
const color = new ArrayBuffer(96);
let opts = { alphaType: 0, editable: true, pixelFormat: 4, scaleMode: 1, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts)
.then( pixelmap => {
this._PixelMap = pixelmap;
})
Image(this._pixelMap)
.width(500)
.height(500)
.objectFit(ImageFit.Cover)
}
.width('100%')
}
.height('100%')
testNapi.testGetImageInfo(this._PixelMap);
console.info("Test GetImageInfo success");
testNapi.testAccessPixels(this._PixelMap);
console.info("Test AccessPixels success");
testNapi.testUnAccessPixels(this._PixelMap);
console.info("Test UnAccessPixels success");
})
}
.width('100%')
}
.height('100%')
}
}
```
......@@ -12,12 +12,12 @@ The following scenarios are common for native purgeable memory development:
## Available APIs
| API| Description|
| API| Description|
| -------- | -------- |
| OH_PurgeableMemory \*OH_PurgeableMemory_Create(size_t size, OH_PurgeableMemory_ModifyFunc func, void \*funcPara) | Creates a **PurgeableMemory** object. A new **PurgeableMemory** object is generated each time this API is called.|
| bool OH_PurgeableMemory_Destroy(OH_PurgeableMemory \*purgObj) | Destroys a **PurgeableMemory** object.|
| bool OH_PurgeableMemory_BeginRead(OH_PurgeableMemory \*purgObj) | Begins a read operation on a **PurgeableMemory** object.|
| void OH_PurgeableMemory_EndRead(OH_PurgeableMemory \*purgObj) | Ends a read operation on a **PurgeableMemory** object and decreases the reference count of the object by 1. When the reference count reaches 0, the object can be reclaimed by the system.|
| OH_PurgeableMemory \*OH_PurgeableMemory_Create(size_t size, OH_PurgeableMemory_ModifyFunc func, void \*funcPara) | Creates a **PurgeableMemory** object. A new **PurgeableMemory** object is generated each time this API is called.|
| bool OH_PurgeableMemory_Destroy(OH_PurgeableMemory \*purgObj) | Destroys a **PurgeableMemory** object.|
| bool OH_PurgeableMemory_BeginRead(OH_PurgeableMemory \*purgObj) | Begins a read operation on a **PurgeableMemory** object.|
| void OH_PurgeableMemory_EndRead(OH_PurgeableMemory \*purgObj) | Ends a read operation on a **PurgeableMemory** object and decreases the reference count of the object by 1. When the reference count reaches 0, the object can be reclaimed by the system.|
|bool OH_PurgeableMemory_BeginWrite(OH_PurgeableMemory \*purgObj) | Begins a write operation on a **PurgeableMemory** object.|
|void OH_PurgeableMemory_EndWrite(OH_PurgeableMemory \*purgObj)|Ends a write operation on a **PurgeableMemory** object and decreases the reference count of the object by 1. When the reference count reaches 0, the object can be reclaimed by the system.|
|void \*OH_PurgeableMemory_GetContent(OH_PurgeableMemory \*purgObj)|Obtains the memory data of a **PurgeableMemory** object.|
......@@ -35,34 +35,32 @@ The following steps describe how to use the native purgeable memory APIs to appl
struct ParaData{
int start;
int end;
}
};
// Declare a function for modifying the object.
bool FactorialFunc(void* data, size_t size, void* param){
bool ret = true;
int oriData = *(int*)(data);
int i = param->start;
while(i<param->end){
oriData *= i;
}
*data = oriData;
if(oriData < 0)
ret = false;
return ret;
bool ret = true;
ParaData *pdata = (ParaData*) param;
int* oriData = (int*)data;
int i = pdata->start;
while(i<pdata->end){
*oriData *= i;
}
return ret;
}
// Declare the parameters of the extended function for modifying the object.
struct AppendParaData{
int newPara;
}
};
// Declare the extended function for modifying the object.
bool AddFunc(void* data, size_t size, void* param){
bool ret = true;
int oriData = *(int*)(data);
oriData += param->newPara;
*data = oriData;
return ret;
bool ret = true;
int *oriDatap = (int*) data;
AppendParaData* apData = (AppendParaData*)param;
*oriDatap += apData->newPara;
return ret;
}
```
2. Create a **PurgeableMemory** object.
......@@ -74,11 +72,14 @@ The following steps describe how to use the native purgeable memory APIs to appl
struct ParaData pdata = {1,2};
// Create a PurgeableMemory object.
OH_PurgableMmory* pPurgmem = OH_PurgableMmory_Create(DATASIZE, FactorialFunc, &pdata);
OH_PurgeableMemory* pPurgmem = OH_PurgeableMemory_Create(DATASIZE, FactorialFunc, &pdata);
```
3. Perfrom a read operation on the **PurgeableMemory** object.
```c++
// Define an object type based on the service requirements.
class ReqObj;
// Begin a read operation on the object.
OH_PurgeableMemory_BeginRead(pPurgmem);
......@@ -94,8 +95,11 @@ The following steps describe how to use the native purgeable memory APIs to appl
4. Perform a write operation on the **PurgeableMemory** object.
```c++
// Define an object type based on the service requirements.
class ReqObj;
// Begin a write operation on the object.
OH_PurgeableMemory_BeginWrite(pPurgmem)
OH_PurgeableMemory_BeginWrite(pPurgmem);
// Obtain the object data.
ReqObj* pReqObj = (ReqObj*) OH_PurgeableMemory_GetContent(pPurgmem);
......
# @ohos.application.formBindingData (formBindingData)
# @ohos.app.form.formBindingData (formBindingData)
The **FormBindingData** module provides APIs for widget data binding. You can use the APIs to create a **FormBindingData** object and obtain related information.
......@@ -12,6 +12,19 @@ The **FormBindingData** module provides APIs for widget data binding. You can us
import formBindingData from '@ohos.app.form.formBindingData';
```
## ProxyData<sup>10+</sup>
Defines the subscription information about the widget update by proxy.
**System capability**: SystemCapability.Ability.Form
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | string | Yes| Subscriber ID of the widget update by proxy. The value is the same as that of the data publisher.|
| subscriberId | string | No| Subscription condition of the widget update by proxy. The default value is the current widget ID (specified by **formId**).|
## FormBindingData
Describes a **FormBindingData** object.
......@@ -21,7 +34,7 @@ Describes a **FormBindingData** object.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| data | Object | Yes| Data to be displayed on the JS widget. The value can be an object containing multiple key-value pairs or a string in JSON format.|
| proxies<sup>10+</sup> | Array<[ProxyData](#proxydata)> | No| Subscription information of the widget update by proxy. The default value is an empty array.|
## createFormBindingData
......@@ -62,3 +75,14 @@ try {
console.error(`catch error, code: ${error.code}, message: ${error.message}`);
}
```
## ProxyData
Defines the widget proxy data.
**System capability**: SystemCapability.Ability.Form
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the proxy. The value depends on the data publisher.|
| subscriberId | string | No| Subscriber ID. The value depends on the data publisher. The default value is the current widget ID.|
......@@ -46,9 +46,11 @@ Adhere to the following constraints and rules when using transient tasks:
- **Quota mechanism**: To prevent abuse of the keepalive, each application has a certain quota every day (dynamically adjusted based on user habits). The default quota for a single day is 10 minutes, and the maximum quota for each request is 3 minutes. After using up the quota, an application cannot request transient tasks. Therefore, applications should cancel their request immediately after the transient tasks are complete, to avoid quota consumption. (Note: The quota refers to the requested duration and does not include the time when the application runs in the background.)
## Continuous Tasks
Continuous tasks provide background running lifecycle support for services that can be directly perceived by users and need to run in the background. For example, if a service needs to play audio or continue with navigation and positioning in the background, which can be perceived by users, it can execute a continuous task in the respective background mode.
### Background Mode Classification
OpenHarmony provides 9 background modes for services that require continuous task execution.
**Table 1** Background modes for continuous tasks
......@@ -66,6 +68,7 @@ OpenHarmony provides 9 background modes for services that require continuous tas
| taskKeeping | Computing task | A computing task is running | Effective only for specific devices |
### Restrictions on Using Continuous Tasks
- If a user triggers a perceivable task, such as broadcasting and navigation, the corresponding background mode is triggered. When the task is started, the system forcibly displays a notification to the user.
- If the task is complete, the application should exit the background mode. If the system detects that an application is not using the resources in the corresponding background mode when the application is running in the background, the application is suspended.
- Ensure that the requested continuous task background mode matches the application type. If the background mode does not match the application type, the system will suspend the task once it detects the issue.
......@@ -73,6 +76,7 @@ OpenHarmony provides 9 background modes for services that require continuous tas
- An ability can request only one continuous task at a time. If an application has multiple abilities, you can request a continuous task for each ability.
## Work Scheduler Tasks
The Work Scheduler provides a mechanism for an application to execute a non-real-time task, for example, data learning, when the system is idle. The system places the Work Scheduler tasks requested by applications in a queue and determines the optimal scheduling time of each task based on the storage space, power consumption, temperature, and more. Persistence is supported. This means that a requested Work Scheduler task can be triggered when the application exits or the device restarts.
### Restrictions on Using Work Scheduler Tasks
......@@ -103,6 +107,7 @@ The use of the Work Scheduler must comply with the following restrictions and ru
- The carried parameters can be of the number, string, or boolean type.
## Efficiency Resources
Efficiency resources are classified into software (WORK_SCHEDULER, COMMON_EVENT, and TIMER) and hardware resources (CPU, GPS, BLUETOOTH, and AUDIO).
An application can perform different operations based on the requested efficiency resources.
......@@ -126,6 +131,7 @@ An application can perform different operations based on the requested efficienc
| AUDIO | 64 | AUDIO resources, which prevent audio resources from being proxied when the application is suspended. |
### Restrictions on Using Efficiency Resources
- Applications or processes are responsible for requesting and releasing efficiency resources. A process can release the resources requested by itself, whereas an application can release the resources requested by both itself and its processes. For example, an application requests CPU resources, and its process requests CPU and WORK_SCHEDULER resources. If the application initiates CPU resource release, the CPU resources requested by the process are also released. However, the WORK_SCHEDULER resources are not released. If the process initiates CPU resource release, the CPU resources requested by the application are retained until being released by the application.
- If persistent resources and non-persistent resources of the same type are requested, the persistent resources overwrite the non-persistent resources and they will not be released upon a timeout. For example, if an application first requests 10-second CPU resources and then requests persistent CPU resources at the 5th second, the CPU resources become persistent and will not be released at the tenth second. If the application releases the CPU resources at the 8th second, both types of CPU resources are released.
- The WORK_SCHEDULER resources can be requested and released by applications, but not by processes.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册