Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/133.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在C+中旋转PNG图像+; 我对C++很陌生。< /P>_C++_Arrays_Image_Rotation_Png - Fatal编程技术网

在C+中旋转PNG图像+; 我对C++很陌生。< /P>

在C+中旋转PNG图像+; 我对C++很陌生。< /P>,c++,arrays,image,rotation,png,C++,Arrays,Image,Rotation,Png,我有一个PNG图像,我正试图旋转180度 图像将另存为新文件 我写了一些代码,但遇到了麻烦,任何关于如何继续的提示都将不胜感激。代码如下,请提前感谢 #include <QCoreApplication> #include <iostream> #include "ImageHandle.h" using namespace std; void rotatedImage (unsigned PixelGrid[WIDTH][HEIGHT]); int main(in

我有一个PNG图像,我正试图旋转180度

图像将另存为新文件

我写了一些代码,但遇到了麻烦,任何关于如何继续的提示都将不胜感激。代码如下,请提前感谢

#include <QCoreApplication>
#include <iostream>
#include "ImageHandle.h"

using namespace std;

void rotatedImage (unsigned PixelGrid[WIDTH][HEIGHT]);

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
const char LogoFile[] = "Airplane.png";

unsigned PixelGrid[WIDTH][HEIGHT];     // Image loaded from file

// If the file cannot be loaded ...
if (!loadImage(PixelGrid, LogoFile))
{
    // Display an error message
    cout << "Error loading file \"" << LogoFile << "\"" << endl;
}
else
{
    cout << "File \"" << LogoFile << "\" opened successfully" << endl;

    // Demo of use of saveImage - to create a copy as "Airplane.png"
    // This should be modified to save the new images as specified
    if (saveImage(PixelGrid, "AirplaneCopy.png"))
    {
        cout << "File \"AirplaneCopy.png\" saved successfully" << 
endl;
    }
    else
    {
        cout << "Could not save \"AirplaneCopy.png\"" << endl;
    }
}

rotatedImage(PixelGrid);

{
    if (saveImage(PixelGrid, "AirplaneRotated.png"))
    {
        cout << "\nFile\"AirplaneRotated.png\" saved successfully" << 
endl;
    }
    else
    {
        cout << "\nCould not save \"AirplaneRotated.png\"" << endl;
    }
}

return a.exec();
}

void rotatedImage (unsigned PixelGrid[WIDTH][HEIGHT])
{
int row;
int col;

for (row = 0; row < WIDTH; row++)
{
    for (col = 0; col < HEIGHT; col++)
    {
        PixelGrid[row][col] = 
    }
}
}
#包括
#包括
#包括“ImageHandle.h”
使用名称空间std;
void rotateImage(无符号像素栅格[宽度][高度]);
int main(int argc,char*argv[])
{
qcorea应用程序(argc、argv);
const char LogoFile[]=“plannier.png”;
未签名的PixelGrid[宽度][高度];//从文件加载的图像
//如果无法加载文件。。。
如果(!loadImage(像素网格,LogoFile))
{
//显示错误消息

cout如果您需要它将图片旋转180度,我想您可以在一半图片上使用简单的循环,并在每次迭代中交换1对像素上的位置

让我们看看位置
(i,j)
-旋转后它应该在哪里?因为它是180,所以它应该在
(宽度-i,高度-j)
,所以你的
旋转图像应该如下所示:

void rotatedImage (unsigned PixelGrid[WIDTH][HEIGHT])
{
    int row;
    int col;

    for (row = 0; row < WIDTH/2; row++)// because you only have to loop on half the image
    {
        for (col = 0; col < HEIGHT; col++) 
        {
            unsigned temp = PixelGrid[row][col];
            PixelGrid[row][col] = PixelGrid[WIDTH - row][HEIGHT - col];
            PixelGrid[WIDTH - row][HEIGHT - col] = temp;
        }
    }
}
void rotateImage(无符号像素栅格[宽度][高度])
{
int行;
int col;
for(row=0;row

我不是
c++
专家,所以我希望我没有语法错误,而且我从来没有检查过这一点,所以请注意,从索引数组中我可能错过了180度旋转很容易做到

您需要像这样翻转阵列

Original Flipped rows and Finally Flipped cols [0][0 , 1, 2] [2][0, 1, 2] [2][2, 1, 0] [1][0 , 1, 2] [1][0, 1, 2] [1][2, 1, 0] [2][0 , 1, 2] [0][0, 1, 2] [0][2, 1, 0] 最初翻转行,最后翻转列 [0][0 , 1, 2] [2][0, 1, 2] [2][2, 1, 0] [1][0 , 1, 2] [1][0, 1, 2] [1][2, 1, 0] [2][0 , 1, 2] [0][0, 1, 2] [0][2, 1, 0]
只需将数组中的行和列朝另一个方向翻转即可。

是否将其旋转45度?180度?如果使用Qt,则应查看QImage::transformed()函数。@JLewis很好-堆栈溢出我们希望每篇文章有一个问题-所以我建议你打开新问题,我会看一看。如果我的文章对你有帮助-请将其标记为已接受(我文章左侧的“v”标记)所以其他人可能会使用它。请不要破坏你的帖子,你正在使那些帮助过你的人的工作无效。@Damien-我没有任何错误