Image처리를 하다보면 memory buffer에 있는 image raw데이터를 BMP포멧으로 저장할 필요가 있다.
RGB Buffer(24bit)를 widows bitmap format으로 저장하는 함수
// _fname : 저장할 파일 명( xxx.bmp )
// _buf : RGB 순서로 구성된 Image buff
// _w, _h : image width, height
void saveBMPfile(char *_fname, uchar* _buf, int _w, int _h)
{
int filesize = 54 + _w * _h * 3;
unsigned char bmpfileheader[14] = {'B','M', 0,0,0,0, 0,0, 0,0, 54,0,0,0};
unsigned char bmpinfoheader[40] = {40,0,0,0, 0,0,0,0, 0,0,0,0, 1,0, 8,0};
unsigned char bmppad[3] = {0,0,0};
bmpfileheader[ 2] = (unsigned char)(filesize );
bmpfileheader[ 3] = (unsigned char)(filesize>> 8);
bmpfileheader[ 4] = (unsigned char)(filesize>>16);
bmpfileheader[ 5] = (unsigned char)(filesize>>24);
bmpinfoheader[ 4] = (unsigned char)( _w );
bmpinfoheader[ 5] = (unsigned char)( _w>> 8);
bmpinfoheader[ 6] = (unsigned char)( _w>>16);
bmpinfoheader[ 7] = (unsigned char)( _w>>24);
bmpinfoheader[ 8] = (unsigned char)( _h );
bmpinfoheader[ 9] = (unsigned char)( _h>> 8);
bmpinfoheader[10] = (unsigned char)( _h>>16);
bmpinfoheader[11] = (unsigned char)( _h>>24);
FILE* fp;
fp =fopen(_fname, "wb");
if(fp!=NULL) {
fwrite(bmpfileheader, 1, 14, fp);
fwrite(bmpinfoheader, 1, 40, fp);
fwrite(_buf, _w*_h, 3, fp);
fclose(fp);
}
}
* Gray Bufferer 저장하기 : 링크
0 comments:
댓글 쓰기