|
|
typedef struct
{
long imageSize;
long blank;
long startPosition;
}BmpHead;
typedef struct
{
long Length;
long width;
long height;
WORD colorPlane;
WORD bitColor;
long zipFormat;
long realSize;
long xPels;
long yPels;
long colorUse;
long colorImportant;
}InfoHead;
struct CPosition
{
int x;
int y;
};
CPosition *Pos = NULL;
void LoadBMP(char *FileName)
{
BmpHead headBMP;
InfoHead infoHead;
FILE* p;
char* filename = FileName;
p = fopen(filename,"rb");
if (p == NULL)
{
return;
}
fseek(p,2,SEEK_CUR);
fread(&headBMP,1,12,p);
fread(&infoHead,1,40,p);
if (infoHead.colorUse != 0)
{
fclose(p);
MessageBox(NULL,"This is not a binarized BMP file.","ERROR",MB_OK);
}
long w=infoHead.width;
long h=infoHead.height;
long nData = infoHead.realSize;
BYTE* pColorData = new BYTE[nData];
fread(pColorData,1,nData,p);
Pos = new CPosition[nData];
int Pixel = 0;
int a = 0,b=0;
int bmpSIZE = 0;
for(int i=0; i<h; i++)
{
for(int j=0; j<w; j++)
{
Pixel = pColorData[w*(h-i)+ j];
if(Pixel == 0)
{
Pos[bmpSIZE].x = j;
Pos[bmpSIZE].y = i;
bmpSIZE++;
}
}
}
if( pColorData )
{
delete []pColorData;
pColorData = NULL;
}
int leftData = 0;
char ch = 0;
while (!feof(p))
{
fread(&ch,1,1,p);
leftData++;
}
if(!fclose(p))
{
}
}
Pos用于存储符合要求的像素的位置,但在数组的开头和结尾保存的数据不正确,是哪里出了问题?哪位哥们知道的说一下
|
|