Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Win32 GDI+
Hi,
 
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.
Posted 20-Nov-12 1:26am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
JackDingler at 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 at 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 at 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: bad
good
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.
  Permalink  
Comments
rswapna28 at 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 at 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 at 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.
eg.,
graphics.translateTransform(x, y);
graphics.rotateTransform(angle);
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 at 22-Nov-12 11:26am
   
Can't you just add your offsets to x,y?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

1) You may use Affine Transformation for this kind of processing.
 
http://en.wikipedia.org/wiki/Affine_transformation[^]
 
2) I think it is better to use some free third party as well:
http://www.artuxsoft.com/download.aspx[^]
  Permalink  
Comments
rswapna28 at 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)

  Print Answers RSS
0 OriginalGriff 304
1 Sergey Alexandrovich Kryukov 255
2 Maciej Los 250
3 Shweta N Mishra 216
4 PIEBALDconsult 174
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,665


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 21 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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