找不到CS50 Pset4中的错误反映?
我为reflect编写了这段代码,当我使用check50时,我得到了以下信息:找不到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 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个像素的正确反射并不意味着它们都是正确的
也就是说,这里有三条改进代码的建议:
j
来实现这一点image[i][j]
而不是image[i][j].rgbtRed
和所有其他颜色。在涉及颜色失真的其他部分,您需要处理颜色请注意,您的交换实际上不是交换,而是分配。由于您正在读取和写入同一图像,因此最终会将图像的一半复制到另一半,并反转。然后将后半部分重新复制回上半部分,但由于此时它是对称的,所以它什么也不做。您可能只想将宽度增加到
width/2
,并对每个像素进行真正的交换。制作一个2x2的图像。对于代码中的每个步骤,绘制图像如何更改。你很快就会发现你的代码有很大的问题。如果我的答案对你有帮助,请接受它,这样其他人就可以更容易地找到正确的答案。