简单易用的图像库stb_image
[编程开发]STB image读取学习
stb-image首页https://www.oschina.net/p/stb-image)
采用的加解码库:stb_image
官方:http://nothings.org/
stb_image.h用于解析图片格式:
#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;
}