0

hi please take a look at my code i think an missing something because its not resizing correctly

BITMAPFILEHEADER bf; fread(&bf, sizeof(BITMAPFILEHEADER), 1, inptr);

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


BITMAPFILEHEADER bf_new = bf;
BITMAPINFOHEADER bi_new = bi;

// bf_new.bfSize = 54 +bi_new.biSizeImage; bf_new.bfSize = bi_new.biSizeImage + sizeof(BITMAPINFOHEADER) + sizeof(BITMAPFILEHEADER); bi_new.biWidth = bi.biWidth * n; bi_new.biHeight = bi.biHeight * n;

// 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;
}

// write outfile's BITMAPFILEHEADER

fwrite(&bf, sizeof(BITMAPFILEHEADER), 1, outptr);


// write outfile's BITMAPINFOHEADER

fwrite(&bi, sizeof(BITMAPINFOHEADER), 1, outptr);

// determine padding for scanlines
int padding =  (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
int newpadding = (4 -(bi_new.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;

bf_new.bfSize = 54 + (bi_new.biWidth * abs(bi_new.biHeight) * sizeof(RGBTRIPLE)) + abs(bi_new.biHeight) * newpadding;
bi_new.biSizeImage = sizeof(RGBTRIPLE) + newpadding;
// iterate over infile's scanlines
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
{
    // iterate over pixels in scanline
    for (int j = 0; j < bi.biWidth; j++)
    {
        // temporary storage
        RGBTRIPLE triple;

        // read RGB triple from infile
         fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
         for (int l = 0; l < n; l++) {
              for (int m = 0; m < n; m++){

        // write RGB triple to outfile
        fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
1

Do you think it might have something to do with calculating the new bfSize and biSizeImage after you write the headers out to the output file?

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

| improve this answer | |

You must log in to answer this question.

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