Question

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 ..

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

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

Someone have a solution to this ?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top