0

my program compiles and the dimensions of the resized document are fine; the problem lies in the colors. About half the pixels are fine but everything else is variously colored and I don't have any idea how, I've checked and rechecked my code. I am aware this question has been asked many times and I've checked many answers yet the difference in implementation makes the answers somewhat confusing for me. If anyone could tell me what I'm doing wrong I'd be grateful.

int a = 0;   
// iterate over infile's scanlines    
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)    
{
    RGBTRIPLE array[out_bi.biWidth];       
 // 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);

        // write RGB triple to array
        array[a] = triple;
        a++;
    }
    for (int y = 0; y < n; y++)
    {
        for (int d = 0; d <= a; d++)
        {
            for (int x = 0; x < n; x++)
            {
                fwrite(&array[d], sizeof(RGBTRIPLE), 1, outptr);
            }
        }
        for (int k = 0; k < out_padding; k++)
        {
            fputc(0x00, outptr);
        }
    }
    // skip over padding, if any
    fseek(inptr, padding, SEEK_CUR);
}
0

Your RGBTRIPLE array[out_bi.biWidth]; could be RGBTRIPLE array[bi.biWidth];, but that's only wasted memory and won't break your code.

The main mistake is to not reset a. Move the int a = 0;, or at least a = 0;, into the loop, so it starts fresh at 0 in each iteration.

Another mistake is with for (int d = 0; d <= a; d++). You would have to use d < a, or if you want d < bi.width, but with a < and not <=.

You must log in to answer this question.

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