Hi. I don't understand why I can't export this bmp file properly. I just basically got a bmp file name from the user, transferred the data to a double pointer and copied it back to a new file to be saved.
But when I run it, and try to open the new image, it says, 'invalid image format'. I don't know what to do anymore
Help pls.
ifile is where i fopened the input file which is lena.bmp
Thanks
Code:
char **idata = malloc( sizeof( char *)*( (*iheader).height) );
int irow, icol, count = 0;
int a = 0;
for ( irow = 0; irow < (*iheader).height; irow++ ){
idata[irow] = malloc( sizeof(char)*( roundto4s( (iheader->width)*3 ) ) );
}
//STORING IMAGE DATA FOR REALZZZ
for ( irow = 0; irow < ( *iheader ).height; irow++ ){
for ( icol = 0; icol < roundto4s( ( ( *iheader ).width )*3); icol++ ){
a = fread( &(idata[irow][icol]), 1, 1, ifile);
if ( a == 1 )
count++;
}
}
if ( count != iheader->sizeimage)
printf("a = %d. HAHAHAHA loser.\n", a);
printf("%c", idata[100][100]);
//EXPORTING IMAGE
FILE *nfile;
count = 0;
nfile = fopen("lena_edited.bmp", "w+b");
fseek(ifile, 0, SEEK_SET);
a = fwrite(ifile, 1, fheader->offset, nfile);
if ( a != fheader->offset )
printf("a = %d. HAHAHAHA loser.\n", a);
fseek(ifile, fheader->offset, SEEK_SET);
a = fwrite(ifile, 1, iheader->sizeimage, nfile);
if ( a != iheader->sizeimage )
printf("a = %d. HAHAHAHA loser.\n", a);