Click here to Skip to main content
14,421,993 members
Rate this:
Please Sign up or sign in to vote.
See more:

I am working on GDI+ for the first time.

Can anyone please tell me how to rotate the image at a point and then translate it towards x(left-right) and y(top-bottom) however the rotation is.

Rotation and translation points keep on changes on key press.

Please help me out in how to do it.
Thanks in advance.
Rate this:
Please Sign up or sign in to vote.

Solution 1

Try this method[^].
JackDingler 20-Nov-12 11:07am
That modifies the image. It looked to me like the question was on drawing the image at arbitrary rotations and coordinates.

Is there a way with GDI+ to rotate an image 15 degrees and offset it by (30, 40) for display?
rswapna28 21-Nov-12 1:32am
Yes there are API's to rotate and translate but both together are not working fine. So I thought I will get help :)
Richard MacCutchan 21-Nov-12 3:24am
Help with what? You need to provide more details of your problem. Use the "Improve Question" link and try to explain exactly what you are trying to do and why it is not working.
Rate this:
Please Sign up or sign in to vote.

Solution 2

That's actually a complicated question with a lot of parts.

GDI+ is a difficult platform for implementing this on, since it doesn't recognize textures, vectors or meshes.

Your basic steps are...

1. Rotate and translate the four corners of the image.
2. Loop through the image reading the pixels.
a. In the outer loop, iterator the rows.
b. In the inner loop iterate the columns.
c. Do the same for the pixel positions for the drawing image.
3. Write the pixels to the GDI+ DC.

Now this is slow. But you have two major areas for optimizations here.

1. There are optimizations and many line drawing algorithms for tracing the pixels of the output image. But most share a common quality. They calculate the coordinates in an indirect fashion. These techniques fill up chapters in books.

2. Make a second memory image that is big enough to hold the entire rotated image and write this, instead of the DC. Then bitblt it to the DC when done.
rswapna28 21-Nov-12 1:37am
GDI+ is a library which is created on top of GDI. It is a 2D graphics library. So I can load any image and do rotate, translate and many more operations on it. I dont have to apply as a texture as OpenGL does and pixel tracing is also not needed.

My problem is, I could not rotate and translate the local coordinates together.
JackDingler 21-Nov-12 9:42am
The translation is a matter of specifying where you want the image drawn. It's the X,Y coordinates you specify on the destination DC.

The only rotation I see in the current library, rotates the image in 90 degree increments. Is there another function for this?

rswapna28 22-Nov-12 0:50am
RotateTransform will rotate the image in any angle. But the issue i am facing is.
I want to rotate the image in point so I am translating my axis to that point and then rotate and translate back again.
graphics.translateTransform(x, y);
graphics.translateTransform(-x, -y);

Now I want my image move towards left. so I used translateTransform to move. But As my image has rotated to some angle so my movement instead global left movement, it is local left movement.

I hope I am clear.
JackDingler 22-Nov-12 11:26am
Can't you just add your offsets to x,y?
Rate this:
Please Sign up or sign in to vote.

Solution 3

1) You may use Affine Transformation for this kind of processing.[^]

2) I think it is better to use some free third party as well:[^]
rswapna28 22-Nov-12 0:55am
Thanks for the help.

I dont know how to go about the Affine transformation but I have applied Eulers method. And the third party library you have given is for .NET project. But mine is VC++.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100