【发布时间】:2021-08-12 05:19:00
【问题描述】:
这个程序正确地反映了图像:
void reflect(int height, int width, RGBTRIPLE image[height][width])
{
int wide=round(width/2);
for(int i=0;i<height;i++){
for (int j=0;j<=wide;j++){
RGBTRIPLE k=image[i][j];
image[i][j]=image[i][(width-j-1)];
image[i][width-j]=k;
}
}
return;
}
但是当我对此运行 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..."
:( blur correctly filters middle pixel
expected "127 140 149\n", not "120 140 150\n"
不知道是什么原因。
【问题讨论】:
-
如果 check50 出现错误,则它不能正确反映图像。不用四舍五入,第二个for循环的条件应该是
<。 -
我已经测试过它可以正确地反映图像。但是我的代码有什么问题
-
有两个选项,您的代码不正确或 check50 已损坏。这些也不匹配:
image[i][j]=image[i][(width-j-1)];和image[i][width-j]=k;您在第二个中缺少-1。 -
你是如何测试的?您是否测试了不是其自身镜像的 1x2 图像?