PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Rotating Images

Hi!

I have problems rotating an image (jpg or gif) 90 degrees. I'm making a sofware with .net framework.

I know that this is not related with games, but microsoft don't give us any solution to do this, only pixel by pixel so I need more than a minute to rotate an image.

Rotating images is usual in game programming,

can anybody tell me a quick way to rotate an image?


Thanks
I find it very hard to believe that it could take over a minute to rotate an image. What size image are you rotating? If performance is your concern then you should be using a real language like C / C++ instead of .NET (tm)(c)(r)(patent pending).

When it comes to operations of this sort you want to work with 32 bits at a time, and try to use the cache to your advantage. However I have no idea how that applies to .net.

Dan East
angedelamort · 31 Mar 2004, 21:38 UTC
even with .Net framework, it should take less than 1 second :P
What are you doing exactly?
Hi!

Thanks for the responses.


I load the image using de Bitmap class, and the problem is that there is no way to access to the image bytes, so I can`t make a quick routine to rotate the image.
I have found only one solution (microsoft gave me it directly in his newsgroups) in wich they rotate the image point by point, and you have to make a call to the api for every point (simply terrible). This is the "fantastic" routine:

int x = 0;
int y = 0;

int dstX = x + bmp.Height - 1;
int dstY = y;
Rectangle src = new Rectangle(0, 0, 1, 1);
for (int r = 0; r < bmp.Height; r++)
{
for (int c = 0; c < bmp.Width; c++)
{
e.Graphics.DrawImage(bmp, dstX, dstY, src, GraphicsUnit.Pixel);
src.X++;
dstY++;
}
dstY = y;
dstX--;
src.X = 0;
src.Y++;
}

I know that gapi give solutions to load bitmaps, but my application needs to load jpg files, and rotate it of course.

Is there any possible solution ??


Thanks for all
Holy crap, no wonder it's so slow. :?

I load the image using de Bitmap class, and the problem is that there is no way to access to the image bytes


How about the "GetPixel"/"SetPixel" functions? GetPixel from the source, SetPixel in a destination bitmap, and then use e.Graphics.DrawImage() to throw the result at the graphics context. If you're rotating 90/180 degrees you could even swap the pixels in the same bitmap (if you wanted to conserve memory).
Hi!

I have seen a lot of posts of people that uses the setpixel / getpixel metods but they have the same problem... too slow, they get resulst as bad as mine.


Thanks
This example demonstrates how to load a bitmap from a file, draw it to a surface, allow the user to modify it, and then save it to a file. In the .NET Compact Framework, there is no simple method for saving Bitmap objects or getting a bitmap handle from a Bitmap object so it is necessary to use a bit of trickery to access a bitmap's pixel data. This example will access a bitmap's pixel data through a device context created from an editor control.


<a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=554ACD82-D87D-43C6-A984-8C625387B198&displaylang;=en">Might be useful.</a>