stb-imageC 开发的图像读取解析库
C 语言开发的一个简单易用的图像读取解析库,也是 Duilib 上用到的图像解析库。
使用示例代码如下:
#include <stdio.h>
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
int main(int argc, char** argv)
{
    int w, h, n;
    //rgba
    //load image
    unsigned char *data = stbi_load("rgba.png", &w, &h, &n, 0);
    printf("%d, %d, %d\n", w, h, n);
    //change pixel
    //rgba,write 10 red pixel at line 11
    for (int dx = 0; dx < 10; ++dx)
    {
        data[n * w * 10 + dx * n + 0] = 255;
        data[n * w * 10 + dx * n + 1] = 0;
        data[n * w * 10 + dx * n + 2] = 0;
        data[n * w * 10 + dx * n + 3] = 255;
    }
    
    //write image
    stbi_write_png("write.png", w, h, n, data, w * 4);
    stbi_image_free(data);
    return 0;
} 
开源协议是 public domain 和 MIT。
评论
