c++ - 正确翻转/镜像图像像素?

标签 c++

http://tinypic.com/r/fwubzc/5

这表明翻转应该是什么,镜子应该是什么。

两种镜像的代码:

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;
            }
    }
}

这看起来适合镜子吗?

对于翻转,只需要使用 widthheight 不除以 2 即可?

最佳答案

您需要使用 width-1-x 而不是 width-x,并且 height-1-y 而不是 高度-y。否则,对于 x==0,您将尝试索引数组外的 [width]。

关于c++ - 正确翻转/镜像图像像素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2647376/

相关文章:

c++ - 如何将类中的函数放入线程中? (使用 Boost 的 C++)

C++:MsiOpenDatabase 失败并出现错误 110 0x6e ERROR_OPEN_FAILED 仅当提升/管理时

c++ - 找出类型

c++ - 当我使用 [=] 捕获(使用 Lambda 类)时,为什么变量会变为 'const'?

c++ - Eigen: 逗号初始化动态矩阵

c++ - 如何重载 == 运算符以允许它用于多重比较?

c++ - 在 C++ 中获取 const char * 长度的最佳方法

c++ - Opencv 应用程序在运行时崩溃,错误代码为 0x0000142

c++ - 从 C 到 C++ 并返回

c++ - 重载 C++ STL 方法