这表明翻转应该是什么,镜子应该是什么。
两种镜像的代码:
void mirrorLeftRight()
{
for (int x = 0; x < width/2; x++) {
for (int y = 0; y < height; y++) {
int temp = pixelData[x][y];
pixelData[x][y]=pixelData[width-x][y]
pixelData[width-x][y]=temp;
}
}
}
void mirrorUpDown()
{
for (int x = 0; x < width; x++) {
for (int y = 0; y < height/2; y++) {
int temp = pixelData[x][y];
pixelData[x][y]=pixelData[x][height-y]
pixelData[x][height-y]=temp;
}
}
}
这看起来适合镜子吗?
对于翻转,只需要使用 width
和 height
不除以 2 即可?
最佳答案
您需要使用 width-1-x
而不是 width-x
,并且 height-1-y
而不是 高度-y
。否则,对于 x==0,您将尝试索引数组外的 [width]。
关于c++ - 正确翻转/镜像图像像素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2647376/