| Name | Date | Size | #Lines | LOC | ||
|---|---|---|---|---|---|---|
| .. | - | - | ||||
| AppScope/ | 06-May-2025 | - | 34 | 32 | ||
| entry/ | 06-May-2025 | - | 1,911 | 1,549 | ||
| hvigor/ | 06-May-2025 | - | 37 | 36 | ||
| screenshot/ | 06-May-2025 | - | ||||
| .gitignore | D | 06-May-2025 | 133 | 12 | 12 | |
| README.md | D | 06-May-2025 | 3.2 KiB | 77 | 56 | |
| build-profile.json5 | D | 06-May-2025 | 1.8 KiB | 68 | 68 | |
| code-linter.json5 | D | 06-May-2025 | 957 | 34 | 34 | |
| hvigorfile.ts | D | 06-May-2025 | 842 | 21 | 5 | |
| oh-package.json5 | D | 06-May-2025 | 808 | 25 | 24 | |
| ohosTest.md | D | 06-May-2025 | 671 | 11 | 7 |
README.md
1# 使用Drawing实现图形绘制与显示(C++) 2 3## 介绍 4 5本工程主要实现了对以下指南文档中 https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/graphics/drawing-guidelines.md 示例代码片段的工程化,主要目标是实现指南中示例代码需要与sample工程文件同源。 6 7## 效果预览 8 9|  |  | 10|--------------------------| ------------------------ | 11 12使用说明 13 141. 该工程可以选择在模拟器和开发板上运行。 152. 点击构建,即可在生成的应用中点击对应的按钮进行图案的绘制。 163. 进入”DocsSample/Drawing/NDKDrawing/entry/src/ohosTest/ets/test/DrawingAbility.test.ets“文件,可以对本项目进行UI的自动化测试。 17 18## 工程目录 19 20``` 21NDKDrawing 22├──entry/src/main 23│ ├──cpp // C++代码区 24│ │ ├──CMakeLists.txt // CMake配置文件 25│ │ ├──hello.cpp // Napi模块注册 26│ │ ├──common 27│ │ │ └──log_common.h // 日志封装定义文件 28│ │ ├──plugin // 生命周期管理模块 29│ │ │ ├──plugin_manager.cpp 30│ │ │ └──plugin_manager.h 31│ │ ├──samples // samples渲染模块 32│ │ │ ├──sample_bitmap.cpp 33│ │ │ └──sample_bitmap.h 34│ ├──ets // ets代码区 35│ │ ├──entryability 36│ │ │ ├──EntryAbility.ts // 程序入口类 37| | | └──EntryAbility.ets 38| | ├──interface 39│ │ │ └──XComponentContext.ts // XComponentContext 40│ │ └──pages // 页面文件 41│ │ └──Index.ets // 主界面 42| ├──resources // 资源文件目录 43``` 44 45## 具体实现 46 471. 利用Native XComponent来获取NativeWindow实例、获取布局/事件信息、注册事件回调并通过Drawing API实现在页面上绘制形状。功能主要包括点击按钮绘制一个五角星和“Hello World Drawing”文字。 482. 通过在IDE中创建Native c++ 工程,在c++代码中定义对外接口为drawPattern和drawText,在js侧调用该接口可在页面上绘制出一个五角星和“Hello World Drawing”文字。 493. 在XComponent的OnSurfaceCreated回调中获取NativeWindow实例并初始化NativeWindow环境。调用OH_NativeXComponent_GetXComponentSize接口获取XComponent的宽高,并以此为输入调用Drawing相关的绘制接口在NativeWindow上绘制出一个五角星和文字。 50 51## 相关权限 52 53无。 54 55## 依赖 56 57不涉及。 58 59## 约束和限制 60 611. 本示例支持标准系统上运行,支持设备:RK3568。 622. 本示例支持API14版本SDK,版本号:5.0.2.57。 633. 本示例已支持使DevEco Studio 5.0.1 Release (构建版本:5.0.5.306,构建 2024年12月6日)编译运行。 64 65## 下载 66 67如需单独下载本工程,执行如下命令: 68 69``` 70git init 71git config core.sparsecheckout true 72echo code/DocsSample/Drawing/NDKDrawing/ > .git/info/sparse-checkout 73git remote add origin https://gitee.com/openharmony/applications_app_samples.git 74git pull origin master 75``` 76 77