Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED] Image rotation  (Read 3326 times)

0 Members and 1 Guest are viewing this topic.

nihohit

  • Newbie
  • *
  • Posts: 37
    • View Profile
[SOLVED] Image rotation
« on: April 10, 2012, 11:00:38 am »
I'm working in SFML.net and I'm trying to create images from image tiles. Sometimes I need to rotate the tiles, and since I'm trying to create new images, and I can't do it on the Sprite level. I tried writing code to do it manually, but the code fails without an error message on the SetPixel command. Anyone got any idea why?


        private static Image rotate270(Image temp)
        {
            uint maxY = temp.Size.Y;
            uint maxX = temp.Size.X;
            Image val = new Image(maxY, maxX);
            for (uint x = 0; x < maxX; x++)
            {
                for (uint y = 0; y < maxY; y++)
                {
                    val.SetPixel(y, maxX - x, temp.GetPixel(x, y));
                }
            }
            return val;
        }

        private static Image rotate90(Image temp)
        {
            uint maxY = temp.Size.Y;
            uint maxX = temp.Size.X;
            Image val = new Image(maxY, maxX);
            for (uint x = 0; x < maxX; x++)
            {
                for (uint y = 0; y < maxY; y++)
                {
                    val.SetPixel(maxY-y, x, temp.GetPixel(x, y));
                }
            }
            return val;
        }

        private static Image rotate180(Image temp)
        {
            uint maxY = temp.Size.Y;
            uint maxX = temp.Size.X;
            Image val = new Image(maxX, maxY);
            for (uint x = 0; x < maxX; x++)
            {
                for (uint y = 0; y < maxY; y++)
                {
                    val.SetPixel(maxX-x, maxY-y, temp.GetPixel(x, y));
                }
            }
            return val;
        }
« Last Edit: April 12, 2012, 03:42:50 pm by nihohit »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Image rotation
« Reply #1 on: April 10, 2012, 11:09:45 am »
maxX - x == maxX when x == 0, and row maxX is invalid (the last one is maxX - 1). Same for Y.
Laurent Gomila - SFML developer

nihohit

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: Image rotation
« Reply #2 on: April 10, 2012, 11:13:16 am »
OUCH. I feel really stupid for that.
Sorry for the hassle.

 

anything