Nov 21, 2018 at 8:57pm UTC
Every pixel gets swapped twice. You swap the first pixel and the last pixel.... and at the end, you swap the last pixel and the first pixel.
Edit: As LC says, you also aren't calling the function :p
Last edited on Nov 21, 2018 at 9:03pm UTC
Nov 21, 2018 at 8:58pm UTC
Well, you haven't actually called the routine that you presumably intend to rotate the image.
Nov 21, 2018 at 9:12pm UTC
JLewise wrote:how will I go about calling this function then
rotatedImage(PixelGrid);
Somewhere around line 47.
what should I remove so that I am not swapping the pixels at the start and finish
Many ways. If it's not square then maybe just guide it with the top half:
for (row = 0; row < WIDTH / 2 ; row++)
(EDIT - needs a bit more thought if WIDTH is odd. Hmm.)
I'm getting mighty confused by WIDTH describing the number of rows and HEIGHT the number of columns. Somebody in your other thread has already said that, I think.
Where are WIDTH and HEIGHT defined? Your code isn't legitimate C++ unless they are constants, which rather limits the number of pictures you are going to deal with.
Last edited on Nov 21, 2018 at 9:49pm UTC
Nov 22, 2018 at 2:36pm UTC
God bless SO. They brought the whole thing back.
This isn't quite what was posted here; in the original post here, the rotate function wasn't actually called. Still, pretty close.
I am quite new to C++.
I have a PNG image which I am trying to rotate by 180 degrees.
The image is to be saved as a new file.
I have wrote out a bit of code but hit a brick wall, any tips for how to continue would be appreciated. Code so far is below, thanks in advance.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
#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] =
}
}
}
Last edited on Nov 22, 2018 at 2:38pm UTC
Nov 22, 2018 at 3:04pm UTC
Good detective work! Given the number of deleted posts in the last week it would be nice to have similar here. Google cache is a bit hit-and-miss.
In this instance the OP has chosen to fly his upside-down aircraft somewhere else.