提交 4a117f44 编写于 作者: G ge-yafang

update docs

Signed-off-by: Nge-yafang <geyafang@huawei.com>
上级 93eda80d
此差异已折叠。
......@@ -7,13 +7,14 @@
- [版本说明](../release-notes/Readme.md)
- 快速开始
- 快速入门
- [前言](quick-start/start-overview.md)
- [开发准备](quick-start/start-overview.md)
- [使用eTS语言开发(传统代码方式)](quick-start/start-with-ets.md)
- [使用eTS语言开发(低代码方式)](quick-start/start-with-ets-low-code.md)
- [使用JS语言开发(传统代码方式)](quick-start/start-with-js.md)
- [使用JS语言开发(低代码方式)](quick-start/start-with-js-low-code.md)
- 开发基础知识
- [应用包结构说明](quick-start/package-structure.md)
- [应用包结构说明(FA模型)](quick-start/package-structure.md)
- [应用包结构说明(Stage模型)](quick-start/stage-structure.md)
- [资源文件的分类](quick-start/basic-resource-file-categories.md)
- [SysCap说明](quick-start/syscap.md)
- 开发
......@@ -34,6 +35,7 @@
- [设备使用信息统计](device-usage-statistics/Readme-CN.md)
- [DFX](dfx/Readme-CN.md)
- [国际化](internationalization/Readme-CN.md)
- [Native API的相关指导](napi/Readme-CN.md)
- 工具
- [DevEco Studio(OpenHarmony)使用指南](quick-start/deveco-studio-user-guide-for-openharmony.md)
- 示例教程
......@@ -42,6 +44,11 @@
- API参考
- [组件参考(基于JS扩展的类Web开发范式)](reference/arkui-js/Readme-CN.md)
- [组件参考(基于TS扩展的声明式开发范式)](reference/arkui-ts/Readme-CN.md)
- [接口参考](reference/apis/Readme-CN.md)
- 接口
- [JS(含eTS) API参考](reference/apis/Readme-CN.md)
- Native API
- [OpenHarmony Native API](reference/native-apis/Readme-CN.md)
- [标准库](reference/native-lib/third_party_libc/musl.md)
- [Node_API](reference/native-lib/third_party_napi/napi.md)
- 贡献
- [参与贡献](../contribute/贡献文档.md)
......@@ -21,7 +21,7 @@ wantAgent封装了一个指定行为的意图,可以通过wantAgent.trigger接
import wantAgent from '@ohos.wantAgent';
```
2. 创建WantAgentInfo信息,详细的WantAgentInfo信息数据类型及包含的参数请见[WantAgentInfo文档](../reference/apis/js-apis-wantAgent.md#WantAgentInfo)介绍。
2. 创建WantAgentInfo信息,详细的WantAgentInfo信息数据类型及包含的参数请见[WantAgentInfo文档](../reference/apis/js-apis-wantAgent.md#wantagentinfo)介绍。
```javascript
private wantAgentObj = null //用于保存创建成功的wantAgent对象,后续使用其完成触发的动作
......
# Native API的相关指导
- [Native API在应用工程中的使用指导](napi-guidelines.md)
- [drawing开发指导](drawing-guidelines.md)
- [rawfile开发指导](rawfile-guidelines.md)
# drawing开发指导
## 场景介绍
native drawing模块提供了一系列的接口用于基本图形和字体的绘制。常见的应用场景举例:
* 2D图形绘制。
* 文本绘制和显示。
## 接口说明
| 接口名 | 描述 |
| -------- | -------- |
| OH_Drawing_BitmapCreate (void) | 创建一个位图对象。 |
| OH_Drawing_BitmapBuild (OH_Drawing_Bitmap *, const uint32_t width, const uint32_t height, const OH_Drawing_BitmapFormat *) | 初始化位图对象的宽度和高度,并且为该位图设置像素格式。 |
| OH_Drawing_CanvasCreate (void) | 创建一个画布对象。 |
| OH_Drawing_CanvasBind (OH_Drawing_Canvas *, OH_Drawing_Bitmap *) | 将一个位图对象绑定到画布中,使得画布绘制的内容输出到位图中(即CPU渲染)。 |
| OH_Drawing_CanvasAttachBrush (OH_Drawing_Canvas *, const OH_Drawing_Brush *) | 设置画刷给画布,画布将会使用设置的画刷样式和颜色去填充绘制的图形形状。 |
| OH_Drawing_CanvasAttachPen (OH_Drawing_Canvas *, const OH_Drawing_Pen *) | 设置画笔给画布,画布将会使用设置画笔的样式和颜色去绘制图形形状的轮廓。 |
| OH_Drawing_CanvasDrawPath (OH_Drawing_Canvas *, const OH_Drawing_Path *) | 画一个自定义路径。 |
| OH_Drawing_PathCreate (void) | 创建一个路径对象。 |
| OH_Drawing_PathMoveTo (OH_Drawing_Path *, float x, float y) | 设置自定义路径的起始点位置。 |
| OH_Drawing_PathLineTo (OH_Drawing_Path *, float x, float y) | 添加一条到目标点的线段。 |
| OH_Drawing_PathClose (OH_Drawing_Path *) | 闭合路径,会添加一条到路径起点位置的线段。 |
| OH_Drawing_PenCreate (void) | 创建一个画笔对象。 |
| OH_Drawing_PenSetAntiAlias (OH_Drawing_Pen *, bool) | 设置抗锯齿属性,如果为真则说明画笔会启用抗锯齿功能,在绘制图形时会对图形的边缘像素进行半透明的模糊处理。 |
| OH_Drawing_PenSetWidth (OH_Drawing_Pen *, float width) | 设置画笔的厚度属性,厚度属性描述了画笔绘制图形轮廓的宽度。 |
| OH_Drawing_BrushCreate (void) | 创建一个画刷对象。 |
| OH_Drawing_BrushSetColor (OH_Drawing_Brush *, uint32_t color) | 设置画刷的颜色属性,颜色属性描述了画刷填充图形时使用的颜色,用一个32位(ARGB)的变量表示。 |
| OH_Drawing_CreateTypographyStyle (void) | 创建一个排版对象,用于定义排版样式。 |
| OH_Drawing_CreateTextStyle (void) | 创建一个文本对象,用于定义文本样式。 |
| OH_Drawing_TypographyHandlerAddText (OH_Drawing_TypographyCreate *, const char *) | 设置文本内容。 |
| OH_Drawing_TypographyPaint (OH_Drawing_Typography *, OH_Drawing_Canvas *, double, double) | 显示文本。 |
详细的接口说明请参考[Drawing](../reference/native-apis/_drawing.md)
## 2D图形绘制开发步骤
以下步骤描述了在**OpenHarmony**如何使用 **native drawing** 模块的画布画笔绘制一个基本的2D图形:
1. **创建Bitmap实例**。使用 **drawing_bitmap.h****OH_Drawing_BitmapCreate** 接口创建一个Bitmap实例 **cBitmap**,并使用 **OH_Drawing_BitmapBuild** 指定其长宽大小和像素格式。
```c++
// 创建一个bitmap对象
OH_Drawing_Bitmap* cBitmap = OH_Drawing_BitmapCreate();
// 定义bitmap的像素格式
OH_Drawing_BitmapFormat cFormat {COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUYE};
// 构造对应格式的bitmap
OH_Drawing_BitmapBuild(cBitmap, width, height, &cFormat);
```
2. **创建画布实例**。使用 **drawing_canvas.h****OH_Drawing_CanvasCreate** 接口创建一个画布实例 **cCanvas**,并使用 **OH_Drawing_CanvasBind** 接口将 **cBitmap** 实例绑定到 **cCanvas** 上,后续在画布上绘制的内容会输出到绑定的 **cBitmap** 实例中。
```c++
// 创建一个canvas对象
OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
// 将画布与bitmap绑定,画布画的内容会输出到绑定的bitmap内存中
OH_Drawing_CanvasBind(cCanvas, cBitmap);
// 使用白色清除画布内容
OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
```
3. **构造Path形状**。使用 **drawing_path.h** 提供的接口完成一个五角星形状的构造 **cPath**
```c++
int len = 300;
float aX = 500;
float aY = 500;
float dX = aX - len * std::sin(18.0f);
float dY = aY + len * std::cos(18.0f);
float cX = aX + len * std::sin(18.0f);
float cY = dY;
float bX = aX + (len / 2.0);
float bY = aY + std::sqrt((cX - dX) * (cX - dX) + (len / 2.0) * (len / 2.0));
float eX = aX - (len / 2.0);
float eY = bY;
// 创建一个path对象,然后使用接口连接成一个五角星形状
OH_Drawing_Path* cPath = OH_Drawing_PathCreate();
// 指定path的起始位置
OH_Drawing_PathMoveTo(cPath, aX, aY);
// 用直线连接到目标点
OH_Drawing_PathLineTo(cPath, bX, bY);
OH_Drawing_PathLineTo(cPath, cX, cY);
OH_Drawing_PathLineTo(cPath, dX, dY);
OH_Drawing_PathLineTo(cPath, eX, eY);
// 闭合形状,path绘制完毕
OH_Drawing_PathClose(cPath);
```
4. **设置画笔和画刷样式**。使用 **drawing_pen.h****OH_Drawing_PenCreate** 接口创建一个画笔实例 **cPen**, 并设置抗锯齿、颜色、线宽等属性,画笔用于形状边框线的绘制。使用**drawing_brush.h****OH_Drawing_BrushCreate** 接口创建一个画刷实例 **cBrush**, 并设置填充颜色, 画刷用于形状内部的填充。使用 **drawing_canvas.h****OH_Drawing_CanvasAttachPen****OH_Drawing_CanvasAttachBrush** 接口将画笔画刷的实例设置到画布实例中。
```c++
// 创建一个画笔Pen对象,Pen对象用于形状的边框线绘制
OH_Drawing_Pen* cPen = OH_Drawing_PenCreate();
OH_Drawing_PenSetAntiAlias(cPen, true);
OH_Drawing_PenSetColor(cPen, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0x00, 0x00));
OH_Drawing_PenSetWidth(cPen, 10.0);
OH_Drawing_PenSetJoin(cPen, LINE_ROUND_JOIN);
// 将Pen画笔设置到canvas中
OH_Drawing_CanvasAttachPen(cCanvas, cPen);
// 创建一个画刷Brush对象,Brush对象用于形状的填充
OH_Drawing_Brush* cBrush = OH_Drawing_BrushCreate();
OH_Drawing_BrushSetColor(cBrush, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0xFF, 0x00));
// 将Brush画刷设置到canvas中
OH_Drawing_CanvasAttachBrush(cCanvas, cBrush);
```
5. **绘制Path形状**。使用 **drawing_canvas.h****OH_Drawing_CanvasDrawPath** 接口将五角星绘制到画布上,绘制完毕后不再使用的实例需要调用对应的接口进行销毁。
```c++
// 在画布上画path的形状,五角星的边框样式为pen设置,颜色填充为Brush设置
OH_Drawing_CanvasDrawPath(cCanvas, cPath);
// 销毁创建的对象
OH_Drawing_BrushDestory(cBrush);
OH_Drawing_PenDestory(cPen);
OH_Drawing_PathDestory(cPath);
```
6. **获取像素数据**。使用 **drawing_bitmap.h****OH_Drawing_BitmapGetPixels** 接口获取到画布绑定bitmap实例的像素地址,该地址指向的内存包含画布刚刚绘制的像素数据。
```c++
// 画完后获取像素地址,地址指向的内存包含画布画的像素数据
void* bitmapAddr = OH_Drawing_BitmapGetPixels(cBitmap);
auto ret = memcpy_s(addr, addrSize, bitmapAddr, addrSize);
if (ret != EOK) {
LOGI("memcpy_s failed");
}
// 销毁canvas对象
OH_Drawing_CanvasDestory(cCanvas);
// 销毁bitmap对象
OH_Drawing_BitmapDestory(cBitmap);
```
## 文本绘制显示开发步骤
以下步骤描述了在OpenHarmony中,如何使用**native drawing**模块的文字显示功能:
1. **创建画布和bitmap实例**
```c++
// 创建bitmap
OH_Drawing_Bitmap* cBitmap = OH_Drawing_BitmapCreate();
OH_Drawing_BitmapFormat cFormat {COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
OH_Drawing_BitmapBuild(cBitmap, width, height, &cFormat);
// 创建canvas
OH_Drawing_Canvas* cCanvas = OH_Drawing_CanvasCreate();
OH_Drawing_CanvasBind(cCanvas, cBitmap);
OH_Drawing_CanvasClear(cCanvas, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF));
```
2. **设置排版风格**
```c++
// 选择左对齐/居中对齐等排版属性
OH_Drawing_TypographyStyle* typoStyle = OH_Drawing_CreateTypographyStyle();
OH_Drawing_SetTypographyTextDirection(typoStyle, TEXT_DIRECTION_LTR);
OH_Drawing_SetTypographyTextAlign(typoStyle, TEXT_ALIGN_LEFT);
```
3. **设置文本风格**
```c++
// 设置文字颜色,例如黑色
OH_Drawing_TextStyle* txtStyle = OH_Drawing_CreateTextStyle();
OH_Drawing_SetTextStyleColor(txtStyle, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0x00));
// 设置文字大小、字重等属性
double fontSize = 30;
OH_Drawing_SetTextStyleFontSize(txtStyle, fontSize);
OH_Drawing_SetTextStyleFontWeight(txtStyle, FONT_WEIGHT_400);
OH_Drawing_SetTextStyleBaseLine(txtStyle, TEXT_BASELINE_ALPHABETIC);
OH_Drawing_SetTextStyleFontHeight(txtStyle, 1);
// 设置字体类型等
const char* fontFamilies[] = {"Roboto"};
OH_Drawing_SetTextStyleFontFamilies(txtStyle, 1, fontFamilies);
OH_Drawing_SetTextStyleFontStyle(txtStyle, FONT_STYLE_NORMAL);
OH_Drawing_SetTextStyleLocale(txtStyle, "en");
```
4. **生成最终文字显示效果**
```c++
OH_Drawing_TypographyCreate* handler = OH_Drawing_CreateTypographyHandler(typoStyle,
OH_Drawing_CreateFontCollection());
OH_Drawing_TypographyHandlerPushTextStyle(handler, txtStyle);
// 设置文字内容
const char* text = "OpenHarmony\n";
OH_Drawing_TypographyHandlerAddText(handler, text);
OH_Drawing_TypographyHandlerPopTextStyle(handler);
OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(handler);
// 设置页面最大宽度
double maxWidth = 800.0;
OH_Drawing_TypographyLayout(typography, maxWidth);
// 设置文字显示起始位置
double position[2] = {10.0, 15.0};
OH_Drawing_TypographyPaint(typography, cCanvas, position[0], position[1]);
```
## 相关实例
针对Drawing模块的使用,有以下相关实例可供参考:
* [Drawing模块2D图形绘制](https://gitee.com/openharmony/graphic_standard/blob/master/rosen/samples/2d_graphics/drawing_c_sample.cpp)
* [Drawing模块文本绘制显示](https://gitee.com/openharmony/graphic_standard/blob/master/rosen/samples/text/renderservice/drawing_text_c_sample.cpp)
此差异已折叠。
# rawfile开发指导
## 场景介绍
开发者可以通过本指导了解在OpenHarmony应用中,如何使用rawfile native接口操作rawfile目录和文件。功能包括遍历、打开、搜索、读取和关闭rawfile。
## 接口说明
| 接口名 | 描述 |
| :----------------------------------------------------------- | :--------------------------------------- |
| NativeResourceManager *OH_ResourceManager_InitNativeResourceManager(napi_env env, napi_value jsResMgr) | 初始化native resource manager。 |
| RawDir *OH_ResourceManager_OpenRawDir(const NativeResourceManager *mgr, const char *dirName) | 打开指定rawfile目录。 |
| int OH_ResourceManager_GetRawFileCount(RawDir *rawDir) | 获取指定rawfile目录下的rawfile文件数量。 |
| const char *OH_ResourceManager_GetRawFileName(RawDir *rawDir, int index) | 获取rawfile名字。 |
| RawFile *OH_ResourceManager_OpenRawFile(const NativeResourceManager *mgr, const char *fileName) | 打开指定rawfile文件。 |
| long OH_ResourceManager_GetRawFileSize(RawFile *rawFile) | 获取rawfile文件大小。 |
| int OH_ResourceManager_SeekRawFile(const RawFile *rawFile, long offset, int whence) | 指定rawfile内偏移量。 |
| long OH_ResourceManager_GetRawFileOffset(const RawFile *rawFile) | 获取rawfile偏移量。 |
| int OH_ResourceManager_ReadRawFile(const RawFile *rawFile, void *buf, size_t length) | 读取rawfile文件内容。 |
| void OH_ResourceManager_CloseRawFile(RawFile *rawFile) | 释放rawfile文件相关资源。 |
| void OH_ResourceManager_CloseRawDir(RawDir *rawDir) | 释放rawfile目录相关资源。 |
| bool OH_ResourceManager_GetRawFileDescriptor(const RawFile *rawFile, RawFileDescriptor &descriptor) | 获取rawfile的fd。 |
| bool OH_ResourceManager_ReleaseRawFileDescriptor(const RawFileDescriptor &descriptor) | 释放rawfile的fd。 |
| void OH_ResourceManager_ReleaseNativeResourceManager(NativeResourceManager *resMgr) | 释放native resource manager相关资源。 |
## 开发步骤
1. 添加头文件。
```c++
#include "raw_file_manager.h"
```
2. 使用OH_ResourceManager_InitNativeResourceManager(napi_env env, napi_value jsResMgr)接口获取NativeResourceManager实例。
```js
// js侧传递js resource manager。
import resManager from '@ohos.resourceManager'
import rawfileTest from 'librawFileTest.so'
resManager.getResourceManager().then(resmgr => {
rawfileTest.testRawFile("test", resmgr, (error, value) => {
console.log("test rawFile");
})
});
```
```c++
// C++侧获取解析js侧传递的参数。
NativeResourceManager* nativeResourceManager = nullptr;
std::string path;
if (i == 0 && valueType == napi_string) {
// 解析第一个参数,参数为相对rawfile目录的文件/目录路径。
......
path = buf.data();
} else if (i == 1 && valueType == napi_object) {
// 解析第二个参数,参数为js resource manager。
nativeResourceManager = OH_ResourceManager_InitNativeResourceManager(env, argv[i]);
}
```
3. 根据NativeResourceManager实例,使用OH_ResourceManager_OpenRawDir接口获取RawDir实例。
```c++
RawDir* rawDir = OH_ResourceManager_OpenRawDir(nativeResourceManager, path.c_str());
```
4. 根据RawDir实例,使用OH_ResourceManager_GetRawFileCount接口获取对应目录下的rawfile文件总数 。
```c++
int count = OH_ResourceManager_GetRawFileCount(rawDir);
```
5. 根据RawDir实例,使用OH_ResourceManager_GetRawFileName接口获取目录下对应index的rawfile文件名。
```c++
for (int index = 0; index < count; index++) {
std::string fileName = OH_ResourceManager_GetRawFileName(rawDir, index);
}
```
6. 根据NativeResourceManager实例,使用OH_ResourceManager_OpenRawFile接口获取指定文件名的RawFile实例
```c++
RawFile* rawFile = OH_ResourceManager_OpenRawFile(nativeResourceManager, fileName.c_str());
```
7. 根据RawFile实例,使用OH_ResourceManager_GetRawFileSize接口获取对应rawfile文件大小。
```c++
long rawFileSize = OH_ResourceManager_GetRawFileSize(rawFile);
```
8. 根据RawFile实例,使用OH_ResourceManager_SeekRawFile接口指定rawfile偏移量。
```c++
int position = OH_ResourceManager_SeekRawFile(rawFile, 10, 0);
int position = OH_ResourceManager_SeekRawFile(rawFile, 0 , 1);
int position = OH_ResourceManager_SeekRawFile(rawFile, -10, 2);
```
9. 根据RawFile实例,使用OH_ResourceManager_GetRawFileOffset接口获取rawfile偏移量。
```c++
long rawFileOffset = OH_ResourceManager_GetRawFileOffset(rawFile)
```
10. 根据RawFile实例,使用OH_ResourceManager_ReadRawFile接口读取rawfile文件内容。
```c++
std::unique_ptr<char[]> mediaData = std::make_unique<char[]>(rawFileSize);
long rawFileOffset = OH_ResourceManager_ReadRawFile(rawFile, mediaData.get(), rawFileSize);
```
11. 根据RawFile实例,使用OH_ResourceManager_CloseRawFile接口释放rawfile文件相关资源。
```c++
OH_ResourceManager_CloseRawFile(rawFile);
```
12. 根据RawDir实例,使用OH_ResourceManager_CloseRawDir接口释放rawfile目录相关资源。
```c++
OH_ResourceManager_CloseRawDir(rawDir);
```
13. 根据RawFile实例,使用OH_ResourceManager_GetRawFileDescriptor接口获取rawfile的RawFileDescriptor。
```c++
RawFileDescriptor descriptor;
bool result = OH_ResourceManager_GetRawFileDescriptor(rawFile, descriptor);
```
14. 根据RawFileDescriptor实例,使用OH_ResourceManager_ReleaseRawFileDescriptor接口关闭rawfile的fd。
```c++
OH_ResourceManager_ReleaseRawFileDescriptor(descriptor);
```
15. 根据NativeResourceManager实例,使用OH_ResourceManager_ReleaseNativeResourceManager接口释放native resource manager。
```c++
OH_ResourceManager_ReleaseNativeResourceManager(nativeResourceManager);
```
......@@ -8,7 +8,7 @@
- [使用JS语言开发(低代码方式)](start-with-js-low-code.md)
- 开发基础知识
- [应用包结构说明(FA模型)](package-structure.md)
- [应用包结构说明(Stage模型)](module-structure.md)
- [应用包结构说明(Stage模型)](stage-structure.md)
- [资源文件的分类](basic-resource-file-categories.md)
- [SysCap说明](syscap.md)
# 开发参考
- [基于JS扩展的类Web开发范式](arkui-js/Readme-CN.md)
- [基于TS扩展的声明式开发范式](arkui-ts/Readme-CN.md)
- 接口
- [JS(含eTS) API参考](apis/Readme-CN.md)
- Native API
- [OpenHarmony Native API](./native-apis/Readme-CN.md)
- [标准库](native-lib/third_party_libc/musl.md)
- [Node_API](native-lib/third_party_napi/napi.md)
- [接口](apis/Readme-CN.md)
# Native API
- MyProject
- [Native XComponent](_o_h___native_x_component.md)
- [Native_Bundle](_native___bundle.md)
- [HiLog](_hi_log.md)
- [NativeWindow](_native_window.md)
- [Drawing](_drawing.md)
- [Rawfile](rawfile.md)
- 头文件和结构体
- 头文件
- [drawing_bitmap.h](drawing__bitmap_8h.md)
- [drawing_brush.h](drawing__brush_8h.md)
- [drawing_canvas.h](drawing__canvas_8h.md)
- [drawing_color.h](drawing__color_8h.md)
- [drawing_font_collection.h](drawing__font__collection_8h.md)
- [drawing_path.h](drawing__path_8h.md)
- [drawing_pen.h](drawing__pen_8h.md)
- [drawing_text_declaration.h](drawing__text__declaration_8h.md)
- [drawing_text_typography.h](drawing__text__typography_8h.md)
- [drawing_types.h](drawing__types_8h.md)
- [external_window.h](external__window_8h.md)
- [log.h](log_8h.md)
- [native_interface_bundle.h](native__interface__bundle_8h.md)
- [native_interface_xcomponent.h](native__interface__xcomponent_8h.md)
- [raw_dir.h](raw__dir_8h.md)
- [raw_file.h](raw__file_8h.md)
- 结构体
- [OH_Drawing_BitmapFormat](_o_h___drawing___bitmap_format.md)
- [OH_NativeXComponent_Callback](_o_h___native_x_component___callback.md)
- [OH_NativeXComponent_TouchEvent](_o_h___native_x_component___touch_event.md)
- [OH_NativeXComponent_TouchPoint](_o_h___native_x_component___touch_point.md)
- [RawFileDescriptor](_raw_file_descriptor.md)
此差异已折叠。
# HiLog
## **Overview**
**Description:**
HiLog模块实现日志打印功能。
开发者可以通过使用这些接口实现日志相关功能,输出日志时可以指定日志类型、所属业务领域、日志TAG标识、日志级别等。
\@syscap SystemCapability.HiviewDFX.HiLog
**Since:**
8
## **Summary**
### Files
| File&nbsp;Name | Description |
| -------- | -------- |
| [log.h](log_8h.md) | HiLog模块日志接口定义,通过这些接口实现日志打印相关功能。 |
### Macros
| Macro&nbsp;Name&nbsp;and&nbsp;Value | Description |
| -------- | -------- |
| LOG_DOMAIN&nbsp;&nbsp;&nbsp;0 | 日志所对应的业务领域,用于标识业务的子系统、模块。 |
| LOG_TAG&nbsp;&nbsp;&nbsp;NULL | 字符串常量,标识调用所在的类或者业务。 |
| OH_LOG_DEBUG(type,&nbsp;...)&nbsp;&nbsp;&nbsp;((void)OH_LOG_Print((type),&nbsp;LOG_DEBUG,&nbsp;LOG_DOMAIN,&nbsp;LOG_TAG,&nbsp;__VA_ARGS__)) | DEBUG级别写日志,宏封装接口。 |
| OH_LOG_INFO(type,&nbsp;...)&nbsp;&nbsp;&nbsp;((void)OH_LOG_Print((type),&nbsp;LOG_INFO,&nbsp;LOG_DOMAIN,&nbsp;LOG_TAG,&nbsp;__VA_ARGS__)) | INFO级别写日志,宏封装接口。 |
| OH_LOG_WARN(type,&nbsp;...)&nbsp;&nbsp;&nbsp;((void)OH_LOG_Print((type),&nbsp;LOG_WARN,&nbsp;LOG_DOMAIN,&nbsp;LOG_TAG,&nbsp;__VA_ARGS__)) | WARN级别写日志,宏封装接口。 |
| OH_LOG_ERROR(type,&nbsp;...)&nbsp;&nbsp;&nbsp;((void)OH_LOG_Print((type),&nbsp;LOG_ERROR,&nbsp;LOG_DOMAIN,&nbsp;LOG_TAG,&nbsp;__VA_ARGS__)) | ERROR级别写日志,宏封装接口。 |
| OH_LOG_FATAL(type,&nbsp;...)&nbsp;&nbsp;&nbsp;((void)HiLogPrint((type),&nbsp;LOG_FATAL,&nbsp;LOG_DOMAIN,&nbsp;LOG_TAG,&nbsp;__VA_ARGS__)) | FATAL级别写日志,宏封装接口。 |
### Enumerations
| Enumeration&nbsp;Name | Description |
| -------- | -------- |
| LogType&nbsp;{&nbsp;LOG_APP&nbsp;=&nbsp;0&nbsp;} | 日志类型。 |
| LogLevel&nbsp;{&nbsp;&nbsp;&nbsp;LOG_DEBUG&nbsp;=&nbsp;3,&nbsp;LOG_INFO&nbsp;=&nbsp;4,&nbsp;LOG_WARN&nbsp;=&nbsp;5,&nbsp;LOG_ERROR&nbsp;=&nbsp;6,&nbsp;&nbsp;&nbsp;LOG_FATAL&nbsp;=&nbsp;7&nbsp;} | 日志级别。 |
### Functions
| Function | Description |
| -------- | -------- |
| OH_LOG_Print&nbsp;(LogType&nbsp;type,&nbsp;LogLevel&nbsp;level,&nbsp;unsigned&nbsp;int&nbsp;domain,&nbsp;const&nbsp;char&nbsp;\*tag,&nbsp;const&nbsp;char&nbsp;\*fmt,...)&nbsp;__attribute__((__format__(os_log | int<br/>写日志接口。 |
| OH_LOG_IsLoggable&nbsp;(unsigned&nbsp;int&nbsp;domain,&nbsp;const&nbsp;char&nbsp;\*tag,&nbsp;LogLevel&nbsp;level) | int&nbsp;bool<br/>检查指定业务领域、TAG、级别的日志是否可以打印。 |
## **Details**
## **Macro Definition**
### LOG_DOMAIN
```
#define LOG_DOMAIN 0
```
**Description:**
日志所对应的业务领域,用于标识业务的子系统、模块。
16进制整数,有效范围0x0~0xFFFF,超过自动截掉高位。
### LOG_TAG
```
#define LOG_TAG NULL
```
**Description:**
字符串常量,标识调用所在的类或者业务。
### OH_LOG_DEBUG
```
#define OH_LOG_DEBUG( type, ... ) ((void)OH_LOG_Print((type), LOG_DEBUG, LOG_DOMAIN, LOG_TAG, __VA_ARGS__))
```
**Description:**
DEBUG级别写日志,宏封装接口。
使用时需要先定义日志业务领域、日志TAG,一般在源文件起始处统一定义一次。
**Parameters:**
| Name | Description |
| -------- | -------- |
| type | 日志类型,三方应用日志类型为LOG_APP。 |
| fmt | 格式化字符串,基于类printf格式的增强,支持隐私参数标识,即在格式字符串每个参数中符号后类型前增加{public}、{private}标识。 |
| ... | 与格式字符串里参数类型对应的参数列表,参数数目、参数类型必须与格式字符串中的标识一一对应。 |
**See also:**
[OH_LOG_Print](#oh_log_print)
### OH_LOG_ERROR
```
#define OH_LOG_ERROR( type, ... ) ((void)OH_LOG_Print((type), LOG_ERROR, LOG_DOMAIN, LOG_TAG, __VA_ARGS__))
```
**Description:**
ERROR级别写日志,宏封装接口。
使用时需要先定义日志业务领域、日志TAG,一般在源文件起始处统一定义一次。
**Parameters:**
| Name | Description |
| -------- | -------- |
| type | 日志类型,三方应用日志类型为LOG_APP。 |
| fmt | 格式化字符串,基于类printf格式的增强,支持隐私参数标识,即在格式字符串每个参数中符号后类型前增加{public}、{private}标识。 |
| ... | 与格式字符串里参数类型对应的参数列表,参数数目、参数类型必须与格式字符串中的标识一一对应。 |
**See also:**
[OH_LOG_Print](#oh_log_print)
### OH_LOG_FATAL
```
#define OH_LOG_FATAL( type, ... ) ((void)HiLogPrint((type), LOG_FATAL, LOG_DOMAIN, LOG_TAG, __VA_ARGS__))
```
**Description:**
FATAL级别写日志,宏封装接口。
使用时需要先定义日志业务领域、日志TAG,一般在源文件起始处统一定义一次。
**Parameters:**
| Name | Description |
| -------- | -------- |
| type | 日志类型,三方应用日志类型为LOG_APP。 |
| fmt | 格式化字符串,基于类printf格式的增强,支持隐私参数标识,即在格式字符串每个参数中符号后类型前增加{public}、{private}标识。 |
| ... | 与格式字符串里参数类型对应的参数列表,参数数目、参数类型必须与格式字符串中的标识一一对应。 |
**See also:**
[OH_LOG_Print](#oh_log_print)
### OH_LOG_INFO
```
#define OH_LOG_INFO( type, ... ) ((void)OH_LOG_Print((type), LOG_INFO, LOG_DOMAIN, LOG_TAG, __VA_ARGS__))
```
**Description:**
INFO级别写日志,宏封装接口。
使用时需要先定义日志业务领域、日志TAG,一般在源文件起始处统一定义一次。
**Parameters:**
| Name | Description |
| -------- | -------- |
| type | 日志类型,三方应用日志类型为LOG_APP。 |
| fmt | 格式化字符串,基于类printf格式的增强,支持隐私参数标识,即在格式字符串每个参数中符号后类型前增加{public}、{private}标识。 |
| ... | 与格式字符串里参数类型对应的参数列表,参数数目、参数类型必须与格式字符串中的标识一一对应。 |
**See also:**
[OH_LOG_Print](#oh_log_print)
### OH_LOG_WARN
```
#define OH_LOG_WARN( type, ... ) ((void)OH_LOG_Print((type), LOG_WARN, LOG_DOMAIN, LOG_TAG, __VA_ARGS__))
```
**Description:**
WARN级别写日志,宏封装接口。
使用时需要先定义日志业务领域、日志TAG,一般在源文件起始处统一定义一次。
**Parameters:**
| Name | Description |
| -------- | -------- |
| type | 日志类型,三方应用日志类型为LOG_APP。 |
| fmt | 格式化字符串,基于类printf格式的增强,支持隐私参数标识,即在格式字符串每个参数中符号后类型前增加{public}、{private}标识。 |
| ... | 与格式字符串里参数类型对应的参数列表,参数数目、参数类型必须与格式字符串中的标识一一对应。 |
**See also:**
[OH_LOG_Print](#oh_log_print)
## **Enumeration Type**
### LogLevel
```
enum LogLevel
```
**Description:**
日志级别。
该枚举类型用于定义日志级别。
各级别建议使用方式:
DEBUG:比INFO级别更详细的流程记录,通过该级别的日志可以更详细地分析业务流程和定位分析问题。DEBUG级别的日志在正式发布版本中默认不会被打印,只有在调试版本或打开调试开关的情况下才会打印。
INFO:用来记录业务关键流程节点,可以还原业务的主要运行过程;用来记录非正常情况信息,但这些情况都是可以预期的(如无网络信号、登录失败等)。这些日志都应该由该业务内处于支配地位的模块来记录,避免在多个被调用的模块或低级函数中重复记录。
WARN:发生了较为严重的非预期情况,但是对用户影响不大,程序可以自动恢复或通过简单的操作就可以恢复的问题。
ERROR:程序或功能发生了错误,该错误会影响功能的正常运行或用户的正常使用,可以恢复但恢复代价较高,如重置数据等。
FATAL:重大致命异常,表明程序或功能即将崩溃,故障无法恢复。
| Enumerator | Description |
| -------- | -------- |
| LOG_DEBUG | DEBUG日志级别,使用OH_LOG_DEBUG接口打印 |
| LOG_INFO | INFO日志级别,使用OH_LOG_INFO接口打印 |
| LOG_WARN | WARN日志级别,使用OH_LOG_WARN接口打印 |
| LOG_ERROR | ERROR日志级别,使用OH_LOG_ERROR接口打印 |
| LOG_FATAL | FATAL日志级别,使用OH_LOG_FATAL接口打印 |
### LogType
```
enum LogType
```
**Description:**
日志类型。
该枚举类型用于定义应用开发者可以使用的日志类型。当前有应用日志LOG_APP。
| Enumerator | Description |
| -------- | -------- |
| LOG_APP | 应用日志 |
## **Function**
### OH_LOG_IsLoggable()
```
int bool OH_LOG_IsLoggable (unsigned int domain, const char * tag, LogLevel level )
```
**Description:**
检查指定业务领域、TAG、级别的日志是否可以打印。
**Parameters:**
| Name | Description |
| -------- | -------- |
| domain | 指定日志业务领域。 |
| tag | 指定日志TAG。 |
| level | 指定日志level。 |
**Returns:**
如果指定domain、tag、level日志可以打印则返回true;否则返回false。
### OH_LOG_Print()
```
int OH_LOG_Print (LogType type, LogLevel level, unsigned int domain, const char * tag, const char * fmt, ... )
```
**Description:**
写日志接口。
指定日志类型、日志级别、业务领域、TAG,按照类printf格式类型和隐私指示确定需要输出的变参。
**Parameters:**
| Name | Description |
| -------- | -------- |
| type | 日志类型,三方应用日志类型为LOG_APP。 |
| level | 日志级别,日志级别包括LOG_DEBUG、LOG_INFO、LOG_WARN、LOG_ERROR、LOG_FATAL。 |
| domain | 日志业务领域,16进制整数,范围0x0~0xFFFF。 |
| tag | 日志TAG,字符串,标识调用所在的类或者业务。 |
| fmt | 格式化字符串,基于类printf格式的增强,支持隐私参数标识,即在格式字符串每个参数中符号后类型前增加{public}、{private}标识。 |
| ... | 与格式字符串里参数类型对应的参数列表,参数数目、参数类型必须与格式字符串中的标识一一对应。 |
**Returns:**
大于等于0表示成功;小于0表示失败。
# Native_Bundle
## **Overview**
**Description:**
Describes the Native Bundle.
**Since:**
9
**Version:**
1.0
## **Summary**
### Files
| File&nbsp;Name | Description |
| -------- | -------- |
| [native_interface_bundle.h](native__interface__bundle_8h.md) | Declares&nbsp;the&nbsp;**Bundle**-specific&nbsp;function,&nbsp;including&nbsp;function&nbsp;for&nbsp;obtaining&nbsp;application&nbsp;ID. |
### Functions
| Function | Description |
| -------- | -------- |
| OH_NativeBundle_GetAppIdByBundleName&nbsp;(const&nbsp;char&nbsp;\*bundleName) | char&nbsp;\*<br/>Obtains&nbsp;the&nbsp;application&nbsp;ID&nbsp;based&nbsp;on&nbsp;the&nbsp;given&nbsp;bundle&nbsp;name. |
## **Details**
## **Function**
### OH_NativeBundle_GetAppIdByBundleName()
```
char* OH_NativeBundle_GetAppIdByBundleName (const char * bundleName)
```
**Description:**
Obtains the application ID based on the given bundle name.
**Parameters:**
| Name | Description |
| -------- | -------- |
| bundleName | Indicates&nbsp;the&nbsp;bundle&nbsp;name&nbsp;of&nbsp;the&nbsp;application. |
**Returns:**
Returns the application ID pointer if successfully obtained and needs to be freed; returns nullptr otherwise.
# NativeWindow
## **Overview**
**Description:**
提供NativeWindow功能,主要用来和egl对接
\@syscap SystemCapability.Graphic.Graphic2D.NativeWindow
**Since:**
8
**Version:**
1.0
## **Summary**
### Files
| File&nbsp;Name | Description |
| -------- | -------- |
| [external_window.h](external__window_8h.md) | 定义获取和使用NativeWindow的相关函数 |
### Functions
| Function | Description |
| -------- | -------- |
| OH_NativeWindow_CreateNativeWindowFromSurface&nbsp;(void&nbsp;\*pSurface) | struct&nbsp;NativeWindow&nbsp;\*<br/>创建NativeWindow实例,每次调用都会产生一个新的NativeWindow实例 |
| OH_NativeWindow_DestroyNativeWindow&nbsp;(struct&nbsp;NativeWindow&nbsp;\*window) | void<br/>将NativeWindow对象的引用计数减1,当引用计数为0的时候,该NativeWindow对象会被析构掉 |
| OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer&nbsp;(void&nbsp;\*pSurfaceBuffer) | struct&nbsp;NativeWindowBuffer&nbsp;\*<br/>创建NativeWindowBuffer实例,每次调用都会产生一个新的NativeWindowBuffer实例 |
| OH_NativeWindow_DestroyNativeWindowBuffer&nbsp;(struct&nbsp;NativeWindowBuffer&nbsp;\*buffer) | void<br/>将NativeWindowBuffer对象的引用计数减1,当引用计数为0的时候,该NativeWindowBuffer对象会被析构掉 |
| OH_NativeWindow_NativeWindowRequestBuffer&nbsp;(struct&nbsp;NativeWindow&nbsp;\*window,&nbsp;struct&nbsp;NativeWindowBuffer&nbsp;\*\*buffer,&nbsp;int&nbsp;\*fenceFd) | int32_t<br/>通过NativeWindow对象申请一块NativeWindowBuffer,用以内容生产 |
| OH_NativeWindow_NativeWindowFlushBuffer&nbsp;(struct&nbsp;NativeWindow&nbsp;\*window,&nbsp;struct&nbsp;NativeWindowBuffer&nbsp;\*buffer,&nbsp;int&nbsp;fenceFd,&nbsp;Region&nbsp;region) | int32_t<br/>通过NativeWindow将生产好内容的NativeWindowBuffer放回到Buffer队列中,用以内容消费 |
| OH_NativeWindow_NativeWindowCancelBuffer&nbsp;(struct&nbsp;NativeWindow&nbsp;\*window,&nbsp;struct&nbsp;NativeWindowBuffer&nbsp;\*buffer) | int32_t<br/>通过NativeWindow将之前申请出来的NativeWindowBuffer返还到Buffer队列中,供下次再申请 |
| OH_NativeWindow_NativeWindowHandleOpt&nbsp;(struct&nbsp;NativeWindow&nbsp;\*window,&nbsp;int&nbsp;code,...) | int32_t<br/>设置/获取NativeWindow的属性,包括设置/获取宽高、内容格式等 |
| OH_NativeWindow_GetBufferHandleFromNative&nbsp;(struct&nbsp;NativeWindowBuffer&nbsp;\*buffer) | BufferHandle&nbsp;\*<br/>通过NativeWindowBuffer获取该buffer的BufferHandle指针 |
| OH_NativeWindow_NativeObjectReference&nbsp;(void&nbsp;\*obj) | int32_t<br/>增加一个NativeObject的引用计数 |
| OH_NativeWindow_NativeObjectUnreference&nbsp;(void&nbsp;\*obj) | int32_t<br/>减少一个NativeObject的引用计数,当引用计数减少为0时,该NativeObject将被析构掉 |
| OH_NativeWindow_GetNativeObjectMagic&nbsp;(void&nbsp;\*obj) | int32_t<br/>获取NativeObject的MagicId |
## **Details**
## **Function**
### OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer()
```
struct NativeWindowBuffer* OH_NativeWindow_CreateNativeWindowBufferFromSurfaceBuffer (void * pSurfaceBuffer)
```
**Description:**
创建NativeWindowBuffer实例,每次调用都会产生一个新的NativeWindowBuffer实例
\@syscap SystemCapability.Graphic.Graphic2D.NativeWindow
**Parameters:**
| Name | Description |
| -------- | -------- |
| pSurfaceBuffer | 参数是一个指向生产者buffer的指针,类型为sptr&lt;OHOS::SurfaceBuffer&gt; |
**Returns:**
返回一个指针,指向NativeWindowBuffer的结构体实例
### OH_NativeWindow_CreateNativeWindowFromSurface()
```
struct NativeWindow* OH_NativeWindow_CreateNativeWindowFromSurface (void * pSurface)
```
**Description:**
创建NativeWindow实例,每次调用都会产生一个新的NativeWindow实例
\@syscap SystemCapability.Graphic.Graphic2D.NativeWindow
**Parameters:**
| Name | Description |
| -------- | -------- |
| pSurface | 参数是一个指向生产者ProduceSurface的指针,类型为sptr&lt;OHOS::Surface&gt; |
**Returns:**
返回一个指针,指向NativeWindow的结构体实例
### OH_NativeWindow_DestroyNativeWindow()
```
void OH_NativeWindow_DestroyNativeWindow (struct NativeWindow * window)
```
**Description:**
将NativeWindow对象的引用计数减1,当引用计数为0的时候,该NativeWindow对象会被析构掉
\@syscap SystemCapability.Graphic.Graphic2D.NativeWindow
**Parameters:**
| Name | Description |
| -------- | -------- |
| window | 参数是一个NativeWindow的结构体实例的指针 |
### OH_NativeWindow_DestroyNativeWindowBuffer()
```
void OH_NativeWindow_DestroyNativeWindowBuffer (struct NativeWindowBuffer * buffer)
```
**Description:**
将NativeWindowBuffer对象的引用计数减1,当引用计数为0的时候,该NativeWindowBuffer对象会被析构掉
\@syscap SystemCapability.Graphic.Graphic2D.NativeWindow
**Parameters:**
| Name | Description |
| -------- | -------- |
| buffer | 参数是一个NativeWindowBuffer的结构体实例的指针 |
### OH_NativeWindow_GetBufferHandleFromNative()
```
BufferHandle* OH_NativeWindow_GetBufferHandleFromNative (struct NativeWindowBuffer * buffer)
```
**Description:**
通过NativeWindowBuffer获取该buffer的BufferHandle指针
\@syscap SystemCapability.Graphic.Graphic2D.NativeWindow
**Parameters:**
| Name | Description |
| -------- | -------- |
| buffer | 参数是一个NativeWindowBuffer的结构体实例的指针 |
**Returns:**
BufferHandle 返回一个指针,指向BufferHandle的结构体实例
### OH_NativeWindow_GetNativeObjectMagic()
```
int32_t OH_NativeWindow_GetNativeObjectMagic (void * obj)
```
**Description:**
获取NativeObject的MagicId
\@syscap SystemCapability.Graphic.Graphic2D.NativeWindow
**Parameters:**
| Name | Description |
| -------- | -------- |
| obj | 参数是一个NativeWindow&nbsp;or&nbsp;NativeWindowBuffer的结构体实例的指针 |
**Returns:**
MagicId 返回值为魔鬼数字,每个NativeObject唯一
### OH_NativeWindow_NativeObjectReference()
```
int32_t OH_NativeWindow_NativeObjectReference (void * obj)
```
**Description:**
增加一个NativeObject的引用计数
\@syscap SystemCapability.Graphic.Graphic2D.NativeWindow
**Parameters:**
| Name | Description |
| -------- | -------- |
| obj | 参数是一个NativeWindow&nbsp;or&nbsp;NativeWindowBuffer的结构体实例的指针 |
**Returns:**
GSError 返回值为错误码
### OH_NativeWindow_NativeObjectUnreference()
```
int32_t OH_NativeWindow_NativeObjectUnreference (void * obj)
```
**Description:**
减少一个NativeObject的引用计数,当引用计数减少为0时,该NativeObject将被析构掉
\@syscap SystemCapability.Graphic.Graphic2D.NativeWindow
**Parameters:**
| Name | Description |
| -------- | -------- |
| obj | 参数是一个NativeWindow&nbsp;or&nbsp;NativeWindowBuffer的结构体实例的指针 |
**Returns:**
GSError
### OH_NativeWindow_NativeWindowCancelBuffer()
```
int32_t OH_NativeWindow_NativeWindowCancelBuffer (struct NativeWindow * window, struct NativeWindowBuffer * buffer )
```
**Description:**
通过NativeWindow将之前申请出来的NativeWindowBuffer返还到Buffer队列中,供下次再申请
\@syscap SystemCapability.Graphic.Graphic2D.NativeWindow
**Parameters:**
| Name | Description |
| -------- | -------- |
| window | 参数是一个NativeWindow的结构体实例的指针 |
| buffer | 参数是一个NativeWindowBuffer的结构体实例的指针 |
**Returns:**
GSError 返回值为错误码
### OH_NativeWindow_NativeWindowFlushBuffer()
```
int32_t OH_NativeWindow_NativeWindowFlushBuffer (struct NativeWindow * window, struct NativeWindowBuffer * buffer, int fenceFd, Region region )
```
**Description:**
通过NativeWindow将生产好内容的NativeWindowBuffer放回到Buffer队列中,用以内容消费
\@syscap SystemCapability.Graphic.Graphic2D.NativeWindow
**Parameters:**
| Name | Description |
| -------- | -------- |
| window | 参数是一个NativeWindow的结构体实例的指针 |
| buffer | 参数是一个NativeWindowBuffer的结构体实例的指针 |
| fenceFd | 参数是一个文件描述符句柄,用以同步时序 |
| region | 参数表示一块脏区域,该区域有内容更新 |
**Returns:**
GSError 返回值为错误码
### OH_NativeWindow_NativeWindowHandleOpt()
```
int32_t OH_NativeWindow_NativeWindowHandleOpt (struct NativeWindow * window, int code, ... )
```
**Description:**
设置/获取NativeWindow的属性,包括设置/获取宽高、内容格式等
\@syscap SystemCapability.Graphic.Graphic2D.NativeWindow
**Parameters:**
| Name | Description |
| -------- | -------- |
| window | 参数是一个NativeWindow的结构体实例的指针 |
| code | 操作码 |
**Returns:**
GSError 返回值为错误码
### OH_NativeWindow_NativeWindowRequestBuffer()
```
int32_t OH_NativeWindow_NativeWindowRequestBuffer (struct NativeWindow * window, struct NativeWindowBuffer ** buffer, int * fenceFd )
```
**Description:**
通过NativeWindow对象申请一块NativeWindowBuffer,用以内容生产
\@syscap SystemCapability.Graphic.Graphic2D.NativeWindow
**Parameters:**
| Name | Description |
| -------- | -------- |
| window | 参数是一个NativeWindow的结构体实例的指针 |
| buffer | 参数是一个NativeWindowBuffer的结构体实例的二级指针 |
| fenceFd | 参数是一个文件描述符句柄 |
**Returns:**
GSError 返回值为错误码
# OH_Drawing_BitmapFormat
## **Overview**
**Related Modules:**
[Drawing](_drawing.md)
**Description:**
结构体用于描述位图像素的格式,包括颜色类型和透明度类型
**Since:**
8
**Version:**
1.0
## **Summary**
### Public Attributes
| Public&nbsp;Attribute&nbsp;Name | Description |
| -------- | -------- |
| colorFormat | |
| alphaFormat | |
## **Details**
## **Member Data**
### alphaFormat
```
OH_Drawing_AlphaFormat OH_Drawing_BitmapFormat::alphaFormat
```
**Description:**
描述位图像素的透明度分量
### colorFormat
```
OH_Drawing_ColorFormat OH_Drawing_BitmapFormat::colorFormat
```
**Description:**
描述位图像素的存储格式
# OH_NativeXComponent_Callback
## **Overview**
**Related Modules:**
[Native XComponent](_o_h___native_x_component.md)
**Description:**
Registers the surface lifecycle and touch event callbacks.
**Since:**
8
**Version:**
1.0
## **Summary**
### Public Attributes
| Public&nbsp;Attribute&nbsp;Name | Description |
| -------- | -------- |
| [OnSurfaceCreated](_o_h___native_x_component.md#ga8beefd4b2359680a3106b28227e47d00)&nbsp;)([OH_NativeXComponent](_o_h___native_x_component.md#ga0e676460ec145b81bdb07a97a368a5f1)&nbsp;\*component,&nbsp;void&nbsp;\*window) | |
| [OnSurfaceChanged](_o_h___native_x_component.md#ga7d84244e13477d91cfdade8d9ff8565b)&nbsp;)([OH_NativeXComponent](_o_h___native_x_component.md#ga0e676460ec145b81bdb07a97a368a5f1)&nbsp;\*component,&nbsp;void&nbsp;\*window) | |
| [OnSurfaceDestroyed](_o_h___native_x_component.md#gad32bd08c749422d807ac87c558af6a44)&nbsp;)([OH_NativeXComponent](_o_h___native_x_component.md#ga0e676460ec145b81bdb07a97a368a5f1)&nbsp;\*component,&nbsp;void&nbsp;\*window) | |
| [DispatchTouchEvent](_o_h___native_x_component.md#ga3d40ca63aba381a63435f71f679e1f26)&nbsp;)([OH_NativeXComponent](_o_h___native_x_component.md#ga0e676460ec145b81bdb07a97a368a5f1)&nbsp;\*component,&nbsp;void&nbsp;\*window) | |
# OH_NativeXComponent_TouchEvent
## **Overview**
**Related Modules:**
[Native XComponent](_o_h___native_x_component.md)
## **Summary**
### Public Attributes
| Public&nbsp;Attribute&nbsp;Name | Description |
| -------- | -------- |
| [id](_o_h___native_x_component.md#gac986c10f386a0b55bd813caec06fe190)&nbsp;=&nbsp;0 | |
| [screenX](_o_h___native_x_component.md#ga68fe9ff656e74ae14254523443d85bb1)&nbsp;=&nbsp;0.0 | |
| [screenY](_o_h___native_x_component.md#ga7696e0e1a81787400e187058a1e332f2)&nbsp;=&nbsp;0.0 | |
| [x](_o_h___native_x_component.md#ga9688a76d25bede284e36b7226ec8ad3a)&nbsp;=&nbsp;0.0 | |
| [y](_o_h___native_x_component.md#ga0136d85dae638fbe9baaa69cf67a9833)&nbsp;=&nbsp;0.0 | |
| [type](_o_h___native_x_component.md#ga22f67143e6acdefa5c7fd4ba23f7c2b6)&nbsp;=&nbsp;[OH_NativeXComponent_TouchEventType::OH_NATIVEXCOMPONENT_UNKNOWN](_o_h___native_x_component.md#gga0a8c68dd460d7e801e7c0ff771f09182aff39d23c1412b3b110a19df4893651d3) | |
| [size](_o_h___native_x_component.md#ga723601b60610b546fbdaf29e87575ca2)&nbsp;=&nbsp;0.0 | |
| [force](_o_h___native_x_component.md#ga7c0a450a47231bd55994a970b3750d3f)&nbsp;=&nbsp;0.0 | |
| [deviceId](_o_h___native_x_component.md#ga00660bb31b05cebe8964ba221c24f966)&nbsp;=&nbsp;0 | |
| [timeStamp](_o_h___native_x_component.md#gadd872bda25d5af9327d12d06a70149fd)&nbsp;=&nbsp;0 | |
| [touchPoints](_o_h___native_x_component.md#gab3514bf8d2fa3de8191d4898ee739053)&nbsp;[OH_MAX_TOUCH_POINTS_NUMBER] | |
| [numPoints](_o_h___native_x_component.md#gad8c19c6c2bbb367fa18fffa813e21cc6)&nbsp;=&nbsp;0 | |
# OH_NativeXComponent_TouchPoint
## **Overview**
**Related Modules:**
[Native XComponent](_o_h___native_x_component.md)
## **Summary**
### Public Attributes
| Public&nbsp;Attribute&nbsp;Name | Description |
| -------- | -------- |
| [id](_o_h___native_x_component.md#gafc435f3e8b5acf462b28bae69180d971)&nbsp;=&nbsp;0 | |
| [screenX](_o_h___native_x_component.md#gae96f097ddffb119b824bcd9f59857ea4)&nbsp;=&nbsp;0.0 | |
| [screenY](_o_h___native_x_component.md#ga8fb126875104358f84e17ddd66dbbf60)&nbsp;=&nbsp;0.0 | |
| [x](_o_h___native_x_component.md#ga04e0e65a35a652d86460c82bf0ca02e3)&nbsp;=&nbsp;0.0 | |
| [y](_o_h___native_x_component.md#ga13d254769a362f049243505e84df8fa4)&nbsp;=&nbsp;0.0 | |
| [type](_o_h___native_x_component.md#gac2b852641112bce8de71f080a21a118a)&nbsp;=&nbsp;[OH_NativeXComponent_TouchEventType::OH_NATIVEXCOMPONENT_UNKNOWN](_o_h___native_x_component.md#gga0a8c68dd460d7e801e7c0ff771f09182aff39d23c1412b3b110a19df4893651d3) | |
| [size](_o_h___native_x_component.md#ga9e5a0e118ab61a889126a985be7947dd)&nbsp;=&nbsp;0.0 | |
| [force](_o_h___native_x_component.md#gaf3d4f92022552678d5d81d2396900595)&nbsp;=&nbsp;0.0 | |
| [timeStamp](_o_h___native_x_component.md#gad090e826a0e33a4054f468109a5a729d)&nbsp;=&nbsp;0 | |
| [isPressed](_o_h___native_x_component.md#ga527c92deb88977ae842ffe6fee50d571)&nbsp;=&nbsp;false | |
# RawFileDescriptor
## **Overview**
**Related Modules:**
[Rawfile](rawfile.md)
**Description:**
提供rawfile文件描述符信息
RawFileDescriptor是[OH_ResourceManager_GetRawFileDescriptor](rawfile.md#ga8313a7d4bb361a98ced485346a9be4b1)的输出参数, 涵盖了rawfile文件的文件描述符以及在HAP包中的起始位置和长度。
**Since:**
8
**Version:**
1.0
## **Summary**
### Public Attributes
| Public&nbsp;Attribute&nbsp;Name | Description |
| -------- | -------- |
| fd | |
| start | |
| length | |
## **Details**
## **Member Data**
### fd
```
int RawFileDescriptor::fd
```
**Description:**
rawfile文件描述符
### length
```
long RawFileDescriptor::length
```
**Description:**
rawfile在HAP包中的长度
### start
```
long RawFileDescriptor::start
```
**Description:**
rawfile在HAP包中的起始位置
# 结构体
- **[OH_Drawing_BitmapFormat](_o_h___drawing___bitmap_format.md)**
- **[OH_NativeXComponent_Callback](_o_h___native_x_component___callback.md)**
- **[OH_NativeXComponent_TouchEvent](_o_h___native_x_component___touch_event.md)**
- **[OH_NativeXComponent_TouchPoint](_o_h___native_x_component___touch_point.md)**
- **[RawFileDescriptor](_raw_file_descriptor.md)**
\ No newline at end of file
# drawing_bitmap.h
## **Overview**
**Related Modules:**
[Drawing](_drawing.md)
**Description:**
文件中定义了与位图相关的功能函数
**Since:**
8
**Version:**
1.0
## **Summary**
### Classes
| Classe&nbsp;Name | Description |
| -------- | -------- |
| [OH_Drawing_BitmapFormat](_o_h___drawing___bitmap_format.md) | 结构体用于描述位图像素的格式,包括颜色类型和透明度类型 |
### Functions
| Function | Description |
| -------- | -------- |
| [OH_Drawing_BitmapCreate](_drawing.md#gac2d33ba4b18e71eca8c41c136004ba48)&nbsp;(void) | [OH_Drawing_Bitmap](_drawing.md#ga8ac4e64cd1e2c651d11325e04c72ddeb)&nbsp;\*<br/>函数用于创建一个位图对象。 |
| [OH_Drawing_BitmapDestroy](_drawing.md#ga5c31becccf1d3ad5df5f6bc7d9007b8f)&nbsp;([OH_Drawing_Bitmap](_drawing.md#ga8ac4e64cd1e2c651d11325e04c72ddeb)&nbsp;\*) | void<br/>函数用于销毁位图对象并回收该对象占有内存。 |
| [OH_Drawing_BitmapBuild](_drawing.md#ga699afe9c4d2665cdd21b5d9b6dfed2ec)&nbsp;([OH_Drawing_Bitmap](_drawing.md#ga8ac4e64cd1e2c651d11325e04c72ddeb)&nbsp;\*,&nbsp;const&nbsp;uint32_t&nbsp;width,&nbsp;const&nbsp;uint32_t&nbsp;height,&nbsp;const&nbsp;[OH_Drawing_BitmapFormat](_o_h___drawing___bitmap_format.md)&nbsp;\*) | void<br/>函数用于初始化位图对象的宽度和高度,并且为该位图设置像素格式 |
| [OH_Drawing_BitmapGetWidth](_drawing.md#ga67b83650847ab1f6e79ca122905d55a3)&nbsp;([OH_Drawing_Bitmap](_drawing.md#ga8ac4e64cd1e2c651d11325e04c72ddeb)&nbsp;\*) | uint32_t<br/>该函数用于获取指定位图的宽度 |
| [OH_Drawing_BitmapGetHeight](_drawing.md#gace471d69bec5b152bd4de5fa8504f7fd)&nbsp;([OH_Drawing_Bitmap](_drawing.md#ga8ac4e64cd1e2c651d11325e04c72ddeb)&nbsp;\*) | uint32_t<br/>函数用于获取指定位图的高度 |
| [OH_Drawing_BitmapGetPixels](_drawing.md#gaf007f52cfbcbc63cd02971c6480c55fb)&nbsp;([OH_Drawing_Bitmap](_drawing.md#ga8ac4e64cd1e2c651d11325e04c72ddeb)&nbsp;\*) | void&nbsp;\*<br/>函数用于获取指定位图的像素地址,可以通过像素地址获取到位图的像素数据 |
# drawing_brush.h
## **Overview**
**Related Modules:**
[Drawing](_drawing.md)
**Description:**
文件中定义了与画刷相关的功能函数
**Since:**
8
**Version:**
1.0
## **Summary**
### Functions
| Function | Description |
| -------- | -------- |
| [OH_Drawing_BrushCreate](_drawing.md#ga75e2193d23cf75878c7b2c78d6b23b35)&nbsp;(void) | [OH_Drawing_Brush](_drawing.md#ga178c83de4a084d35c30e4681319ea711)&nbsp;\*<br/>函数用于创建一个画刷对象 |
| [OH_Drawing_BrushDestroy](_drawing.md#ga9dc1d4aa465d06f2d847feddae1558b5)&nbsp;([OH_Drawing_Brush](_drawing.md#ga178c83de4a084d35c30e4681319ea711)&nbsp;\*) | void<br/>函数用于销毁画刷对象并回收该对象占有的内存。 |
| [OH_Drawing_BrushIsAntiAlias](_drawing.md#ga4c861e23b8c0a3fb84d906d81bea5335)&nbsp;(const&nbsp;[OH_Drawing_Brush](_drawing.md#ga178c83de4a084d35c30e4681319ea711)&nbsp;\*) | bool<br/>函数用于获取画刷是否设置抗锯齿属性,如果为真则说明画刷会启用抗锯齿功能,在绘制图形时会对图形的边缘像素进行半透明的模糊处理 |
| [OH_Drawing_BrushSetAntiAlias](_drawing.md#ga41735fc7a2776fbe41c77b3f4637e1c5)&nbsp;([OH_Drawing_Brush](_drawing.md#ga178c83de4a084d35c30e4681319ea711)&nbsp;\*,&nbsp;bool) | void<br/>函数用于设置画刷的抗锯齿属性,设置为真则画刷在绘制图形时会对图形的边缘像素进行半透明的模糊处理 |
| [OH_Drawing_BrushGetColor](_drawing.md#ga29dc1e2442cea7e958a5e037c4cc9f59)&nbsp;(const&nbsp;[OH_Drawing_Brush](_drawing.md#ga178c83de4a084d35c30e4681319ea711)&nbsp;\*) | uint32_t<br/>函数用于获取画刷的颜色属性,颜色属性描述了画刷填充图形时使用的颜色,用一个32位(ARGB)的变量表示 |
| [OH_Drawing_BrushSetColor](_drawing.md#ga4b62aa574623c1a75e14f612a831531b)&nbsp;([OH_Drawing_Brush](_drawing.md#ga178c83de4a084d35c30e4681319ea711)&nbsp;\*,&nbsp;uint32_t&nbsp;color) | void<br/>函数用于设置画刷的颜色属性,颜色属性描述了画刷填充图形时使用的颜色,用一个32位(ARGB)的变量表示 |
# drawing_canvas.h
## **Overview**
**Related Modules:**
[Drawing](_drawing.md)
**Description:**
文件中定义了与画布相关的功能函数
**Since:**
8
**Version:**
1.0
## **Summary**
### Functions
| Function | Description |
| -------- | -------- |
| [OH_Drawing_CanvasCreate](_drawing.md#ga1bfe881a0b018a982678906f3522d4df)&nbsp;(void) | [OH_Drawing_Canvas](_drawing.md#ga086e2de47ef7bfe6c96e6b09e87da33a)&nbsp;\*<br/>函数用于创建一个画布对象 |
| [OH_Drawing_CanvasDestroy](_drawing.md#ga1a3023ccc48a381cc0b4ae09e2d85c38)&nbsp;([OH_Drawing_Canvas](_drawing.md#ga086e2de47ef7bfe6c96e6b09e87da33a)&nbsp;\*) | void<br/>函数用于销毁画布对象并回收该对象占有的内存 |
| [OH_Drawing_CanvasBind](_drawing.md#ga666595bb182a5e31733f4144c1515cae)&nbsp;([OH_Drawing_Canvas](_drawing.md#ga086e2de47ef7bfe6c96e6b09e87da33a)&nbsp;\*,&nbsp;[OH_Drawing_Bitmap](_drawing.md#ga8ac4e64cd1e2c651d11325e04c72ddeb)&nbsp;\*) | void<br/>函数用于将一个位图对象绑定到画布中,使得画布绘制的内容输出到位图中(即CPU渲染) |
| [OH_Drawing_CanvasAttachPen](_drawing.md#gaaec6db563bd7153dc95d0bfab71a4ed1)&nbsp;([OH_Drawing_Canvas](_drawing.md#ga086e2de47ef7bfe6c96e6b09e87da33a)&nbsp;\*,&nbsp;const&nbsp;[OH_Drawing_Pen](_drawing.md#ga88e73d9d7b62e6113237fc0f828910d2)&nbsp;\*) | void<br/>函数用于设置画笔给画布,画布将会使用设置画笔的样式和颜色去绘制图形形状的轮廓 |
| [OH_Drawing_CanvasDetachPen](_drawing.md#ga79321b669f2b5dc0460ca929f00dfc47)&nbsp;([OH_Drawing_Canvas](_drawing.md#ga086e2de47ef7bfe6c96e6b09e87da33a)&nbsp;\*) | void<br/>函数用于去除掉画布中的画笔,使用后画布将不去绘制图形形状的轮廓 |
| [OH_Drawing_CanvasAttachBrush](_drawing.md#ga1b238c829ea5f2ff627766a3e50feaa6)&nbsp;([OH_Drawing_Canvas](_drawing.md#ga086e2de47ef7bfe6c96e6b09e87da33a)&nbsp;\*,&nbsp;const&nbsp;[OH_Drawing_Brush](_drawing.md#ga178c83de4a084d35c30e4681319ea711)&nbsp;\*) | void<br/>函数用于设置画刷给画布,画布将会使用设置的画刷样式和颜色去填充绘制的图形形状 |
| [OH_Drawing_CanvasDetachBrush](_drawing.md#ga7a6b5e56d2492b5641b8b3f634b096fe)&nbsp;([OH_Drawing_Canvas](_drawing.md#ga086e2de47ef7bfe6c96e6b09e87da33a)&nbsp;\*) | void<br/>函数用于去除掉画布中的画刷,使用后画布将不去填充图形形状 |
| [OH_Drawing_CanvasSave](_drawing.md#ga4ebc55405e00ad4b8609303fefc6997a)&nbsp;([OH_Drawing_Canvas](_drawing.md#ga086e2de47ef7bfe6c96e6b09e87da33a)&nbsp;\*) | void<br/>函数用于保存当前画布的状态(画布矩阵)到一个栈顶 |
| [OH_Drawing_CanvasRestore](_drawing.md#gadd632be64ccc2601def753ecc1e53944)&nbsp;([OH_Drawing_Canvas](_drawing.md#ga086e2de47ef7bfe6c96e6b09e87da33a)&nbsp;\*) | void<br/>函数用于恢复保存在栈顶的画布状态(画布矩阵) |
| [OH_Drawing_CanvasDrawLine](_drawing.md#gadf6bae5efd20587612596f8e78a16144)&nbsp;([OH_Drawing_Canvas](_drawing.md#ga086e2de47ef7bfe6c96e6b09e87da33a)&nbsp;\*,&nbsp;float&nbsp;x1,&nbsp;float&nbsp;y1,&nbsp;float&nbsp;x2,&nbsp;float&nbsp;y2) | void<br/>函数用于画一条直线段 |
| [OH_Drawing_CanvasDrawPath](_drawing.md#ga99ebc73abdc27599f4bcc1c1045cb75e)&nbsp;([OH_Drawing_Canvas](_drawing.md#ga086e2de47ef7bfe6c96e6b09e87da33a)&nbsp;\*,&nbsp;const&nbsp;[OH_Drawing_Path](_drawing.md#gab7e53fc0181099b4a0a3e4a08d3c9023)&nbsp;\*) | void<br/>函数用于画一个自定义路径 |
| [OH_Drawing_CanvasClear](_drawing.md#ga7f07cc6f0b223d9b343c133fbb2503f6)&nbsp;([OH_Drawing_Canvas](_drawing.md#ga086e2de47ef7bfe6c96e6b09e87da33a)&nbsp;\*,&nbsp;uint32_t&nbsp;color) | void<br/>函数用于使用指定颜色去清空画布 |
# drawing_color.h
## **Overview**
**Related Modules:**
[Drawing](_drawing.md)
**Description:**
文件中定义了与颜色相关的功能函数
**Since:**
8
**Version:**
1.0
## **Summary**
### Functions
| Function | Description |
| -------- | -------- |
| [OH_Drawing_ColorSetArgb](_drawing.md#ga9137935b970e49ffd813157ebd8bbfb7)&nbsp;(uint32_t&nbsp;alpha,&nbsp;uint32_t&nbsp;red,&nbsp;uint32_t&nbsp;green,&nbsp;uint32_t&nbsp;blue) | uint32_t<br/>函数用于将4个变量(分别描述透明度、红色、绿色和蓝色)转化为一个描述颜色的32位(ARGB)变量 |
# drawing_font_collection.h
## **Overview**
**Related Modules:**
[Drawing](_drawing.md)
**Description:**
定义绘制模块中与fontCollection相关的函数
**Since:**
8
**Version:**
1.0
## **Summary**
### Functions
| Function | Description |
| -------- | -------- |
| [OH_Drawing_CreateFontCollection](_drawing.md#gab54c68359a650cde36b82f021f06c814)&nbsp;(void) | [OH_Drawing_FontCollection](_drawing.md#ga4ce31d04a1580d4f50e87b8695fcebc7)&nbsp;\*<br/>创建OH_Drawing_FontCollection |
| [OH_Drawing_DestroyFontCollection](_drawing.md#ga4791ce4ddfaa3545a797c2ce144c819d)&nbsp;([OH_Drawing_FontCollection](_drawing.md#ga4ce31d04a1580d4f50e87b8695fcebc7)&nbsp;\*) | void<br/>释放被OH_Drawing_FontCollection对象占据的内存 |
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册