随笔 - 632  文章 - 17  评论 - 54  阅读 - 93万

ndk集成stb_image.h

一、概述

  使用步骤:

     1.在ndk入口cpp中加入一个宏。ps:最好加最上面

#include <jni.h>
#include <string>
#define STB_IMAGE_IMPLEMENTATION

     2.在使用的时候导入头文件 

//导入stb_image头文件
#include "stb_image.h"

 

二、代码示例

  stbi_load方法,传入图像的路径,可以拿到图像的宽、高和通道数(channel)

复制代码
void loadDataFromFile(const char *fileName,
                          std::function<void(int, int, unsigned char *)> imgDataFunc) {
        int type = 0;
        int width = 0;
        int height = 0;
        //stbi_set_flip_vertically_on_load(true);//如果图像有镜像可以用开启这个翻转
        unsigned char *picData = stbi_load((char const *) fileName, &width, &height, &type,
                                           STBI_rgb_alpha);
        imgDataFunc(width, height, picData);
        stbi_image_free(picData);
    }
复制代码

 

posted on   飘杨......  阅读(58)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
历史上的今天:
2023-09-05 SpringBoot+Nacos+Gateway实现一个端口调用多个不同服务
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示