📄 create_bmp.c
字号:
#include<stdio.h>
struct STBMPInfo
{
unsigned char m_FileType[2];
unsigned long m_FileSize;
unsigned int m_Reserved1;
unsigned int m_Reserved2;
unsigned long m_DataOffset;
unsigned long m_HeaderSize;
unsigned long m_Width;
unsigned long m_Height;
unsigned int m_Planes;
unsigned int m_ColorBits;
unsigned long m_Compression;
unsigned long m_DataSize;
unsigned long m_HResolution;
unsigned long m_VResolution;
unsigned long m_Colors;
unsigned long m_ImportantColors;
};
/*------------------------------------------------------------------
* Function name: displayBMPFile()
* Description : display bmp in gaven position
* Input args : int x, y : start coord, bmp_file : file name
* Return : NONE
* Author :
* Time : 2005/11/18
* History : new
*-----------------------------------------------------------------*/
void createBMPFile( const char *base_file, const char *image_file )
{
struct STBMPInfo bmp_info;
FILE *bmpfp, *srcfp;
unsigned char info_buf[54];
unsigned char buf_line[1600];
int line_size = 1600, data_offset, start_line;
if(( bmpfp = fopen( base_file, "rb+" )) == NULL )
{
printf( "[displayBMPFile]Failed to open bmp file %s ...\n", bmp_file );
return;
}
if(( srcfp = fopen( image_file, "rb" )) == NULL )
{
printf( "[displayBMPFile]Failed to open bmp file %s ...\n", bmp_file );
return;
}
if( fread( info_buf, 1, 54, bmpfp ) < 54 )
{
fprintf( debug_err, "%s-%d[displayBMPFile]Invalid bmp file %s ...\n", _FL_, bmp_file );
fclose( bmpfp );
return;
}
bmp_info.m_FileType[0] = info_buf[0];
bmp_info.m_FileType[1] = info_buf[1];
bmp_info.m_FileSize = info_buf[2] | info_buf[3] << 8 | info_buf[4] << 16 | info_buf[5] << 24;
bmp_info.m_DataOffset = info_buf[10] | info_buf[11] << 8 | info_buf[12] << 16 | info_buf[13] << 24;
bmp_info.m_HeaderSize = info_buf[14] | info_buf[15] << 8 | info_buf[16] << 16 | info_buf[17] << 24;
bmp_info.m_Width = info_buf[18] | info_buf[19] << 8 | info_buf[20] << 16 | info_buf[21] << 24;
bmp_info.m_Height = info_buf[22] | info_buf[23] << 8 | info_buf[24] << 16 | info_buf[25] << 24;
bmp_info.m_Planes = info_buf[26] | info_buf[27] << 8;
bmp_info.m_ColorBits = info_buf[28] | info_buf[29] << 8;
bmp_info.m_Compression = info_buf[30] | info_buf[31] << 8 | info_buf[32] << 16 | info_buf[33] << 24;
bmp_info.m_DataSize = info_buf[34] | info_buf[35] << 8 | info_buf[36] << 16 | info_buf[37] << 24;
bmp_info.m_HResolution = info_buf[38] | info_buf[39] << 8 | info_buf[40] << 16 | info_buf[41] << 24;
bmp_info.m_VResolution = info_buf[42] | info_buf[43] << 8 | info_buf[44] << 16 | info_buf[45] << 24;
bmp_info.m_Colors = info_buf[46] | info_buf[47] << 8 | info_buf[48] << 16 | info_buf[49] << 24;
bmp_info.m_ImportantColors = info_buf[50] | info_buf[51] << 8 | info_buf[52] << 16 | info_buf[53] << 24;
start_line = 599;
data_offset = bmp_info.m_DataOffset + 1600 * start_line;
buf_size = bmp_info.m_Width * bmp_info.m_Height;
while( 1 )
{
memset( buf_line, 0x00, sizeof( buf_line ));
fread( buf_line, 1, line_size, srcfp );
if( fseek( bmpfp, data_offset, 0 ) == -1 )
{
break;
}
write( bmpfp, buf_line, sizeof( buf_line ));
if( feof( srcfp ))
{
break;
}
data_offset -= sizeof( buf_line );
}
fclose( bmpfp );
fclose( srcfp );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -