旋转图像PPM

rotate an image PPM

本文关键字:PPM 图像 旋转      更新时间:2023-10-16

我试图向左/或向右旋转图像ppm。我成功地旋转了180度,但90度似乎不起作用。

这是我的代码

// working 1-D array of pixels pixel
*n_array = new Image(width, height);
// set up the new array dimensions based on ROTATION type
switch (the rotation)
{
    case ROTCW:
    case ROTCCW:
   ...
    break;
    case ROT180:
    default: .. break;
}
for (unsigned int idx = 0; idx < (o_width * o_height); idx++)
{
    old_y = idx / o_width;
    switch (rotation)
    {
        case ROTCCW: ... 
        default: cout << "Oups" << std::endl; break;
    }
    // put pixel into n_array
}

所以这是我的结果…

https://i.stack.imgur.com/Cj6AM.png

https://i.stack.imgur.com/yTnbS.png

有人有解决办法吗?

您可以在创建新图像后翻转图像尺寸。尝试在switch (rotation) {...}之后移动GaryImage *n_array = new GrayImage(o_width, o_height);以使用正确的高度和宽度。

编辑:反正应该是GrayImage *n_array = new GrayImage(n_width, n_height);