0

I did read the following related qsns Resize returns correct sized square, only top half is green and white center isn't there HELP!

When I use peek, student.bmp is similar to staff.bmp but once my bmp gets resized the image is messed up

But they DON'T help my case , Could someone pls look at my code and provide suggestions ?

// change width, height for  outfile header 

bio.biWidth = bi.biWidth * n; 
bio.biHeight = bi.biHeight * n;

// padding new 

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

// determine padding for oufile 
int paddingo = (4 - (bio.biWidth * sizeof(RGBTRIPLE)) % 4) % 4; // paddingo is outfile padding 


// change size of outfile header 
bio.biSizeImage = (bio.biWidth * sizeof(RGBTRIPLE)  + paddingo) * abs(bio.biHeight); 
bfo.bfSize = bfo.bfSize - bi.biSizeImage + bio.biSizeImage;     // Calculate actual image size 

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

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

// I moved the padding line from 79-80 to padding new heading 

// iterate over infile's scanlines
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
{

  // temporary storage
             RGBTRIPLE triple;

for (int p =0; p < n; p++)

{


    // iterate over pixels in scanline
    for (int j = 0; j < bi.biWidth; j++)
    {


        // read RGB triple from infile
        fread(&triple, sizeof(RGBTRIPLE), 1, inptr);


        for (int k = 0; k < n; k++)
            {

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

            }

        // skip over padding, if any
        fseek(inptr, padding, SEEK_CUR);

            // Add a new padding
        for (int l = 0; l < paddingo; l++)

            fputc(0x00, outptr);

            if (j < n-1 )   
        {

         fseek(inptr, -((bi.biWidth* sizeof(RGBTRIPLE)*3) + padding), SEEK_CUR);

        } 

     } // braces for pixel j horizontal 

} // for p loop n times     

} // braces for main loop for Height

// close infile
fclose(inptr);

// close outfile
fclose(outptr);

// that's all folks
return 0;

}

1

The code is writing padding to the output file after every pixel. It should only be writing padding at the end of each row of pixels. To see this, use the xxd tool to compare the output file to the input file.

There are other issues after this, but that's for another question.

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

You must log in to answer this question.

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