writing an image
I'm given a bmp and I'm trying to create a new image and output that to bmp file. I'm not sure if I'm doing it correctly.
Bmp consist of three 3structs:
Header, InfoHeader, Data
I'm able to get the Header,InfoHeader written to the file, but the data is what alludes me. I just get a black image with random lines. All the numbers such as pixeltype,size,etc all match up but the image just won't come out to the orginal. Wondering if there are any image experts that might know something? Thanks
Bool WriteImage(Image im, String filename)
outname = filename;
op = fopen(outname,"w");
int s1 = fwrite((void *)&im.head,sizeof(im.head),1,op);
int s2 = fwrite((void *)&im.infoheader,sizeof(im.infoheader),1,op);
int s3 = fwrite((void *)&im.data,GetTotalSize(im),1, op);
return(s1 && s2 && s3);
Are you modifying the image in any way? Bear in mind that BMP image data is doubleword-aligned, so each line must be exactly divisible by 4. If not, you'll need to add padding bytes to each line.
No, the image isn't getting changed at all. Yes our professo told us about the padding. He said with our bmp that he gave us, we won't have to compensate for that issue. All information from header and infoheader seem correct. We get 'an' image, but it's all black.
In which case your problem is likely to lie outside the WriteImage function (i.e. there's something wrong with im.data).
You shouldn't need to cast to void * either, it literally means "pointer to anything" so any pointer will resolve correctly.