📄 bmp.cpp
字号:
#include "stdafx.h"
#include "bmp.h"
#include "release.h"
int loadBMP(char *filename, unsigned int &width, unsigned int &height, ptype ***Q){
FILE *stream;
ptype **P;
// Open for read (will fail if file "crt_fopen.c" does not exist)
if( fopen_s( &stream, filename, "rb" ) ) {
printf( "The file %s was not opened\n",filename);
return 1;
}
else
printf( "The file %s was opened\n" ,filename);
//data offset
fseek(stream,0xaL,SEEK_SET);
unsigned int location;
fread(&location,4,1,stream);
//width&height
fseek(stream,0x12L,SEEK_SET);
fread(&width,4,1,stream);
fread(&height,4,1,stream);
//bitmap type
fseek(stream,0x1cL,SEEK_SET);
unsigned short bitw;
fread(&bitw,2,1,stream);
//initialize P
P = new ptype *[height];
if (!P) {
printf("Allocate height error.\n");
return 1;
}
for (unsigned int j=0; j<height; j++) {
P[j]=new ptype [width];
if (!P[j]) {
printf("Allocate width error.\n");
return 1;
}
}
//bitmap data
fseek(stream,long(location),SEEK_SET);
for (unsigned int y=0; y<height; y++)
fread(P[height-y-1],1,width,stream);
// Close stream if it is not NULL
if( stream)
{
if ( fclose( stream ) )
{
printf( "The file '%s' was not closed\n",filename );
return 1;
}
}
*Q=P;
return 0;
}
void testLoadBMP()
{
ptype ** P=NULL;
unsigned int w,h;
loadBMP("bmp1.bmp",w,h,&P);
for (unsigned int i=0;i<h;i++){
for (unsigned int j=0;j<w;j++)
printf("%d\t",P[i][j]);
printf("\n");
}
deleteP(P,h);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -