#include #include #include #include "png.h" int main(void) { char *p[256], c[3]; FILE *fp; int i, j, k; png_structp png_ptr; png_infop info_ptr; for (i = 0; i < 256; i++) { p[i] = malloc(3 * 256); } for (i = 0; i < 4; i++) { for (j = 0; j < 64; j++) { for (k = 0; k < 256; k++) { switch (i) { case 0: c[0] = 0; c[1] = 0; c[2] = 255; break; case 1: c[0] = 0; c[1] = 255; c[2] = 0; break; case 2: c[0] = 255; c[1] = 0; c[2] = 0; break; case 3: c[0] = 255; c[1] = 255; c[2] = 255; break; } p[i * 64 + j][k * 3] = c[0]; p[i * 64 + j][k * 3 + 1] = c[1]; p[i * 64 + j][k * 3 + 2] = c[2]; } } } fp = fopen("hogehoge.png", "wb"); assert(fp); png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); assert(png_ptr); info_ptr = png_create_info_struct(png_ptr); assert(info_ptr); png_init_io(png_ptr, fp); png_set_IHDR(png_ptr, info_ptr, 256, 256, 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); png_write_info(png_ptr, info_ptr); png_write_image(png_ptr, p); png_write_end(png_ptr, info_ptr); png_destroy_write_struct(&png_ptr, &info_ptr); return 0; }