Click to See Complete Forum and Search --> : Bitmap help??


anniejohn
March 23rd, 2004, 03:28 AM
I am facing some problem with the .bmp file...My app can load 2 .bmp images and now i need to generate a new .bmp image from that both images....Part of my code is:


pBmp1.bmpHeader.bmpSize=sizeof(BMP);//40;
pBmp1.bmpHeader.bmpWidth=widthPreWarp;
pBmp1.bmpHeader.bmpHeight=heightPreWarp;
pBmp1.bmpHeader.bmpPlanes=1;
pBmp1.bmpHeader.bmpBitCount=24;
pBmp1.bmpHeader.bmpCompression=0;
pBmp1.bmpHeader.bmpSizeImage=((((pBmp1.bmpHeader.bmpWidth * pBmp1.bmpHeader.bmpBitCount) + 31) & ~31) / 8) * pBmp1.bmpHeader.bmpHeight;//0;
pBmp1.bmpHeader.bmpXPixPMeter=0;
pBmp1.bmpHeader.bmpYPixPMeter=0;
pBmp1.bmpHeader.bmpClrAmt=0;
pBmp1.bmpHeader.bmpClrImportant=0;


pBmp1.fHeader.bFileType=19778;
pBmp1.fHeader.bFileSize=sizeof(pBmp1.fHeader)+pBmp1.bmpHeader.bmpSize+pBmp1.bmpHeader.bmpSizeImage;
pBmp1.fHeader.bFileReserved1=0;
pBmp1.fHeader.bFileReserved2=0;
pBmp1.fHeader.bFileOffBits=1078;

pBmp1.createImg(widthPreWarp*heightPreWarp*3);

for(int i=0;i<heightPreWarp;i++){
for(int j=0;j<widthPreWarp;j++){
pBmp1.img[(i*widthPreWarp+j)*3+0]=0;
pBmp1.img[(i*widthPreWarp+j)*3+1]=0;
pBmp1.img[(i*widthPreWarp+j)*3+2]=0;
}
}

FILE *fout;

fout=fopen("PreWarp1.bmp","wb");
while(fout==NULL){
printf("Please enter a valid file\n");
}

long index;
int x;

fwrite(&(pBmp1.fHeader),14/*sizeof(bmpHeader)*/,1,fout);
fwrite(&(pBmp1.bmpHeader),sizeof(unsigned long)+36,1,fout);
for(index=0;index<heightPreWarp;index++)
for(x=0;x<widthPreWarp;x++){
fputc(pBmp1.img[(index*widthPreWarp+x)*3+2],fout);
fputc(pBmp1.img[(index*widthPreWarp+x)*3+1],fout);
fputc(pBmp1.img[(index*widthPreWarp+x)*3+0],fout);
}
fclose(fout);

pBmp1.displayImg(WIDTH/2-widthPreWarp/2,HEIGHT/2+heightPreWarp/2);


All I can get is the new image size i think is correct...But the new image failed to be drawn out when i wanna take a preview in the window explorer...Anyone can help?

clife
March 25th, 2004, 01:31 AM
Maybe...Pixel Martix Indexed error