초간단 bmp 포맷으로 저장
2011-10-19
간단하게 작성해본 bmp 파일 핸들링 예제.
Freeimage 는 정말이지.. 심플하며.. 최고다.
#include <FreeImage.h> void main(void) { FIBITMAP *bitmap = FreeImage_Allocate(512, 512, 32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); if (bitmap) { int bytespp; int y; int x; int width = FreeImage_GetWidth(bitmap); int height = FreeImage_GetHeight(bitmap); int line = FreeImage_GetLine(bitmap); bytespp = line / width; for(y = 0; y < height; y++) { char *bits = FreeImage_GetScanLine(bitmap, y); for(x = 0; x < width; x++) { // Set pixel color to green with a transparency of 128 bits[FI_RGBA_RED] = 0; bits[FI_RGBA_GREEN] = 255; bits[FI_RGBA_BLUE] = 0; bits[FI_RGBA_ALPHA] = 128; // jump to next pixel bits += bytespp; } } FreeImage_Save(FIF_BMP, bitmap, "test.bmp", PNG_DEFAULT); FreeImage_Unload(bitmap); } }
Categorized as: Programming
답글 남기기