4

所以我对这个用于像素化图像的程序有一些问题。一个问题是我得到一个“围绕变量'pixArray'的堆栈已损坏”,然后,当我在中断后单击继续时,它会在标题中出现错误。

我不确定使用 pastebin 是否可以接受,但我会使用它来写一个“短”的帖子。

编码

正在使用的图像

此外,当它通过时,所有像素化正方形在正方形的左侧和顶部都太短了一个像素。它只是在写入 outFile 时使用原始数据。如果您可以尝试找出发生这种情况的原因,您将获得奖励积分。

最后,平均值似乎没有正确平均,运行程序后您可以通过图像最右侧周围的方块看到。

任何这些问题的帮助将不胜感激。提前致谢!

编辑:我对代码进行了排序,注释掉了使用pixArray的部分,而在注释掉时修复问题的部分位于函数的底部,getAveragesForRGB

start = 0;//reset start number
for(int row = 0; row < squareSize; row++) {
    if(row != 0)
        start = ((square * MAXROWS) / (MAXCOLS / squareSize)) + 1;
    stop = (((square + 1) * MAXROWS) / (MAXCOLS / squareSize));
    for (int col = start; col < stop; col++) {
        //write each average into each piece of the array
        pixArray[row][col].red = redAvg;
        pixArray[row][col].green = greenAvg;
        pixArray[row][col].blue = blueAvg;
    }
}

编辑2:我现在一切顺利。以防万一有人出于某种原因遇到这个确切的问题这是getAveragesForRGB我所有问题所在的新问题。

void getAveragesForRGB(Pixel pixArray[][MAXCOLS], int squareSize, int square, int numSquaresPerStripe) {

    //initialize variables needed for function
    int start, stop;
    int redAvg, greenAvg, blueAvg;

    //reset averages for current square's usage
    redAvg = 0;
    greenAvg = 0;
    blueAvg = 0;

    start = 0; //reset start number
    for (int row=0; row < squareSize; row++) {
        if (row != 0)
            start = ((square * MAXROWS) / (MAXCOLS / squareSize)) - 1;  //starting point for loop over the columns
        stop = start + squareSize;//stopping point for   ^^^
        for (int col = start; col < stop - 1; col++) {
            //add each rgb value to the sum to be divided later
            redAvg += pixArray[row][col].red;
            greenAvg += pixArray[row][col].green;
            blueAvg += pixArray[row][col].blue;
        }
    }

    //divide by number of pixels in square for average
    redAvg /= (squareSize * squareSize);
    greenAvg /= (squareSize * squareSize);
    blueAvg /= (squareSize * squareSize);


    start = 0;//reset start number
    for (int row = 0; row < squareSize; row++) {
        if (row != 0)
            start = ((square * MAXROWS) / (MAXCOLS / squareSize)) - 1;  //starting point for loop over the columns
        stop = (((square + 1) * MAXROWS) / (MAXCOLS / squareSize));  //stopping point for   ^^^
        for (int col = start; col < stop - 1; col++) {
            //write each average into each piece of the array
            pixArray[row][col].red = redAvg;
            pixArray[row][col].green = greenAvg;
            pixArray[row][col].blue = blueAvg;
        }
    }
}
4

0 回答 0