Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
找不到CS50 Pset4中的错误反映?_C_Cs50 - Fatal编程技术网

找不到CS50 Pset4中的错误反映?

找不到CS50 Pset4中的错误反映?,c,cs50,C,Cs50,我为reflect编写了这段代码,当我使用check50时,我得到了以下信息: :( reflect correctly filters 1x2 image expected "0 0 255\n255 0...", not "0 0 255\n0 0 2..." :( reflect correctly filters 1x3 image expected "0 0 255\n0 255...", not "

我为reflect编写了这段代码,当我使用check50时,我得到了以下信息:

:( reflect correctly filters 1x2 image
    expected "0 0 255\n255 0...", not "0 0 255\n0 0 2..."

:( reflect correctly filters 1x3 image
    expected "0 0 255\n0 255...", not "0 0 255\n0 255..."

:) reflect correctly filters image that is its own mirror image

:( reflect correctly filters 3x3 image
    expected "70 80 90\n40 5...", not "70 80 90\n40 5..."

:( reflect correctly filters 4x4 image
    expected "100 110 120\n7...", not "100 110 120\n7..."
然而这些数字似乎是一样的

下面是我的反射函数:

/ Reflect image horizontally
void reflect(int height, int width, RGBTRIPLE image[height][width])
{
    //Cycle through rows
    for (int i = 0; i < height; i++)
    {   //Cycle through columns
        for (int j = 0; j < width; j++)
        {   //Swap the current cell with oppsite cell.
            image[i][j].rgbtRed = image[i][width - j - 1].rgbtRed;
            image[i][j].rgbtBlue = image[i][width - j - 1].rgbtBlue;
            image[i][j].rgbtGreen = image[i][width - j - 1].rgbtGreen;
        }    
    }
    
    return;
} 

/水平反射图像
空心反射(整数高度、整数宽度、RGB三重图像[高度][宽度])
{
//在行中循环
对于(int i=0;i
首先,我想指出,check50只显示了一小部分像素;仅仅因为你得到了前2-3个像素的正确反射并不意味着它们都是正确的

也就是说,这里有三条改进代码的建议:

  • 您的目标是将图像的一半移动到另一半。因此,您不希望遍历所有列,因为正如0x5453所说,这将导致您只反射两次,从而使图像保持原样,但只保留其中的一半。您可以通过在第二个for循环中设置
    j
    来实现这一点
  • 记住David Malan的讲座,你需要一个临时杯子来切换两个杯子的内容。因此,您应该将一个临时变量设置为原始像素,然后将原始像素设置为另一侧的一个,然后将另一侧的一个设置为临时变量。这将切换原始像素与另一侧的像素;i、 e.反思
  • 因为您只是切换像素,所以不需要为单个颜色而烦恼;您可以只处理
    image[i][j]
    而不是
    image[i][j].rgbtRed
    和所有其他颜色。在涉及颜色失真的其他部分,您需要处理颜色

  • 请注意,您的交换实际上不是交换,而是分配。由于您正在读取和写入同一图像,因此最终会将图像的一半复制到另一半,并反转。然后将后半部分重新复制回上半部分,但由于此时它是对称的,所以它什么也不做。您可能只想将宽度增加到
    width/2
    ,并对每个像素进行真正的交换。制作一个2x2的图像。对于代码中的每个步骤,绘制图像如何更改。你很快就会发现你的代码有很大的问题。如果我的答案对你有帮助,请接受它,这样其他人就可以更容易地找到正确的答案。