1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
void TForm1::SaveBmp( char *file, TRGBTriple *trgb)
{
BmpMagic magic;
BmpHeader header;
BmpInfo info;
memset( &magic, 0, BMP_MAGIC_SIZE);
memset( &header, 0, BMP_HEADER_SIZE );
memset( &info, 0, BMP_INFO_SIZE );
TRGBTriple* itsRows[272];
for( int i=0; i<272; i++ )
itsRows[i] = &trgb[i*480];
FILE *pFile = fopen( file, "w+" );
if( !pFile )
{
printf("GrContext::SaveBmp error open file %s\n", file );
return;
}
magic.magic[0] = 'B';
magic.magic[1] = 'M';
int width = 480*3;
if( width%4 )
width += 4-width%4;
int size = width*272;
unsigned char data[480*3*272];
int index = 0;
TRGBTriple *row;
for( int i=0; i<272; i++ )
{
index = (272-i-1)*width;
row = itsRows[i];
for( int j=0; j<480; j++, row++ )
{
data[index++] = row->rgbtBlue;
data[index++] = row->rgbtGreen;
data[index++] = row->rgbtRed;
if(i == 200)
i = 200;
}
}
header.size = BMP_MAGIC_SIZE+BMP_HEADER_SIZE+BMP_INFO_SIZE+size;
header.offset = BMP_MAGIC_SIZE+BMP_HEADER_SIZE+BMP_INFO_SIZE;
info.size = BMP_INFO_SIZE;
info.bits_per_pixel = 24;
info.height = 272;
info.image_size = size;
info.width = 480;
info.xresolution = 480;
info.yresolution = 272;
info.planes = 1;
fwrite( &magic, 1, BMP_MAGIC_SIZE, pFile );
fwrite( &header, 1, BMP_HEADER_SIZE, pFile );
fwrite( &info, 1, BMP_INFO_SIZE, pFile );
int x = fwrite( data, 1, size, pFile );
fflush( pFile );
fclose( pFile );
}
|