Reputation: 57
I'm trying to rotate to the left/or to the right an image ppm. I succeeded to rotate 180 degree but the 90 seems not working..
This is my code
// 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
}
So this is my results ..
https://i.sstatic.net/Cj6AM.png
https://i.sstatic.net/yTnbS.png
Someone have a solution to this ?
Upvotes: 0
Views: 983
Reputation: 385
You flip your image dimensions after creating the new image.
Try moving GaryImage *n_array = new GrayImage(o_width, o_height);
after switch (rotation) {...}
to use the correct height and width.
Edit: it should be GrayImage *n_array = new GrayImage(n_width, n_height);
anyway
Upvotes: 1