OpenHarmony图像解码库—stb-image [GN编译]

341 阅读2分钟

简介

stb_image主要是C/C++实现的图像解码库。

下载安装

直接在OpenHarmony-SIG仓中搜索stb-image并下载。

使用说明

以OpenHarmony 3.1 Beta的rk3568版本为例

  1. 库代码存放路径:./third_party/stb-image

  2. 修改添加依赖的编译脚本,路径:/developtools/bytrace_standard/ohos.build

  {
     "subsystem": "developtools",
     "parts": {
       "bytrace_standard": {
         "module_list": [
           "//developtools/bytrace_standard/interfaces/innerkits/native:bytrace_core",
           "//developtools/bytrace_standard/bin:bytrace_target",
           "//developtools/bytrace_standard/bin:bytrace.cfg",
           "//developtools/bytrace_standard/interfaces/kits/js/napi:bytrace",
           "//third_party/stb-image:stb_image",
           "//third_party/stb-image:stb_image_test"
         ],
         "inner_kits": [
           {
             "type": "so",
             "name": "//developtools/bytrace_standard/interfaces/innerkits/native:bytrace_core",
             "header": {
               "header_files": [
                 "bytrace.h"
               ],
               "header_base": "//developtools/bytrace_standard/interfaces/innerkits/native/include"
             }
           }
         ],
          "test_list": [
           "//developtools/bytrace_standard/bin/test:unittest"
         ]
       }
     }
   }

3. 用命令 ./build.sh --product-name rk3568 --ccache 编译

  1. 生成库文件路径:out/rk3568/developtools/profiler,该路径会生成库文件

DD一下:鸿蒙开发学习文档,可关注工粽号<程序猿百晓生>霍取。

1.OpenHarmony开发基础
2.OpenHarmony北向开发环境搭建
3.鸿蒙南向开发环境的搭建
4.鸿蒙生态应用开发白皮书V2.0 & V3.0
5.鸿蒙开发面试真题(含参考答案) 
6.TypeScript入门学习手册
7.OpenHarmony 经典面试题(含参考答案)
8.OpenHarmony设备开发入门【最新版】
9.沉浸式剖析OpenHarmony源代码
10.系统定制指南
11.【OpenHarmony】Uboot 驱动加载流程
12.OpenHarmony构建系统--GN与子系统、部件、模块详解
13.ohos开机init启动流程
14.鸿蒙版性能优化指南
.......

接口说明

  1. 加载图像数据 stbi_write_jpg(char const *filename, int x, int y, int comp, const void *data, int quality)

  2. 修改图像尺寸 stbir_resize(const void *input_pixels , int input_w , int input_h , int input_stride_in_bytes, void *output_pixels, int output_w, int output_h, int output_stride_in_bytes, stbir_datatype datatype, int num_channels, int alpha_channel, int flags, stbir_edge edge_mode_horizontal, stbir_edge edge_mode_vertical, stbir_filter filter_horizontal, stbir_filter filter_vertical, stbir_colorspace space, void *alloc_context)

  3. 将像素数据写入文件 stbi_write_png(char const *filename, int x, int y, int comp, const void *data, int stride_bytes)

  4. 保存 jpg 格式图片 stbi_write_jpg(char const *filename, int x, int y, int comp, const void *data, int quality)

约束与限制

在下述版本验证通过:

DevEco Studio: 3.1Release(3.1.0.200), SDK: API9 Release(3.2.10.6)

目录结构

|---- stb-image   #库的具体实现都在此目录下
|     |---- data   #图片资源
|     |---- deprecated   #弃用代码
|     |---- docs   #文档说明
|     |---- tests   #单元测试用例
|     |---- tools   #工具模块
|     |---- README.md   #安装使用方法