0

Photos are legible, but with this vertical black stripes

// determine biHeight, biWight and padding for infile scanlines
int InPadding =  (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
int biHeightInfile = bi.biHeight;
int biWightInfile = bi.biWidth;
int InfileScanline = InPadding + (biWightInfile * 3);

// determine biHeight, biWight and padding for outfile scanlines
bi.biWidth = bi.biWidth * n;
int OutPadding =  (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
bi.biHeight = bi.biHeight * n;
bi.biSizeImage = abs(bi.biHeight) * (bi.biWidth*3 + OutPadding);
bf.bfSize = bf.bfOffBits + bi.biSizeImage;

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

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

// iterate over infile's scanlines

for (int i = 1; i <= abs(biHeightInfile*n); i++)
{

         // iterate over pixels in infile scanline
        for (int j = 0; j < biWightInfile; j++)
        {
            // temporary storage
            RGBTRIPLE triple; 

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

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

        }
        // skip over padding in infile, if any
        fseek(inptr, InPadding, SEEK_CUR);

        // then add padding zeroes to outfile, if any
        for (int k = 0; k < OutPadding; k++)
        {
            fputc(0x00, outptr);
        }

        //move infile's pointer back to repeat the horizontal resizing
        ......

1 Answer 1

0

Per fwrite's man page

size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);

The function fwrite() writes nmemb elements of data, each size bytes long, to the stream pointed to by stream, obtaining them from the loca‐ tion given by ptr.

Unfortunately this is not the same thing as writing ptr exactly n times into stream. Rather, this means writing exactly nmemb * size bytes from ptr into stream which I don't think what you want.

To fix that, you probably need to use a loop.

You must log in to answer this question.

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