0

I am having difficult perfecting my new headers for resize. Can someone please tell me what I am doing wrong and how to go about fixing it? Here's my header:

        // read infile's BITMAPINFOHEADER
BITMAPINFOHEADER bi;
fread(&bi, sizeof(BITMAPINFOHEADER), 1, inptr);

 // read infile's BITMAPFILEHEADER
BITMAPFILEHEADER bf;
fread(&bf, sizeof(BITMAPFILEHEADER), 1, inptr);

// ensure infile is (likely) a 24-bit uncompressed BMP 4.0
//if (bf.bfType != 0x4d42 || bf.bfOffBits != 54 || bi.biSize != 40 || 
//    bi.biBitCount != 24 || bi.biCompression != 0)
//{
//    fclose(outptr);
//    fclose(inptr);
//    fprintf(stderr, "Unsupported file format.\n");
//    return 4;
//}

// Store original header values
int origbiWidth, origbiHeight, origpadding;
origbiWidth = bi.biWidth;
origbiHeight = bi.biHeight;
origpadding = (4 - (origbiWidth * sizeof(RGBTRIPLE)) % 4) % 4;

// Declare new headers
BITMAPINFOHEADER newbi;
newbi = bi;
BITMAPFILEHEADER newbf;
newbf = bf;

// header redefinition
newbi.biWidth = (bi.biWidth) * n;               //error
newbi.biHeight = (bi.biHeight) * n;             //error
int newpadding = (4 - (newbi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
newbi.biSizeImage = ((sizeof(RGBTRIPLE) * newbi.biWidth) + newpadding) * abs(newbi.biHeight);       //error
newbf.bfSize = newbi.biSizeImage + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);                             //error

// write outfile's BITMAPINFOHEADER
fwrite(&newbi, sizeof(BITMAPINFOHEADER), 1, outptr);

// write outfile's BITMAPFILEHEADER
fwrite(&newbf, sizeof(BITMAPFILEHEADER), 1, outptr);

1 Answer 1

1
newbi.biSizeImage = ((sizeof(BITMAPINFOHEADER) * newbi.biWidth) + newpadding) 
     * abs(newbi.biHeight);       //error

Why on earth are you multiplying biWidth (the width of a line, measured in pixels) times the size of one of the headers?????

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

3
  • I have no idea why i put that there XD. Anyway, I updated the code to be accurate. The header still does not work. Any mistakes you see?
    – Jason_V
    Apr 12, 2017 at 3:45
  • Hmmm. Which header is supposed to be written to the output file first? This is the same problem from a couple days ago.
    – Cliff B
    Apr 12, 2017 at 4:48
  • Oh sorry, completely forgot to fix that. Thanks for the help!
    – Jason_V
    Apr 12, 2017 at 23:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .