• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1451
  • Last Modified:

GDI+ Rotate objects

Hi.

I am new to GDI+ and I am trying to use Graphics :: RotateTransform to rotate some objects. I can rotate the whole DC by some angle, but it rotates it around 0,0.

Two questions:

1. I want to rotate the DC around a specific point of the DC , and not 0,0. Say, I want to rotate around the center so the point would be (rc.right - rc.left)/2 , (rc.bottom - rc.top)/2. Can you provide me sample code to do that ? I 've seen the Matrix and other Graphics :: transform-related stuff, but since I am new to affline transformations I don't understand then pretty well.

2. Can I do the same with just a part of the DC, and not the entire DC ?

Thanks



0
WxW
Asked:
WxW
  • 4
  • 4
1 Solution
 
jkrCommented:
GDI+ uses matrix transformations for that purpose, so if you want to rotate around a point other than (0,0), that is a combination of a translation and a rotation (http://en.wikipedia.org/wiki/Transformation_matrix), i.e.

graphics.TranslateTransform((rc.right - rc.left)/2 , (rc.bottom - rc.top)/2, MatrixOrderPrepend);

graphics.RotateTransform(some_angle,MatrixOrderPrepend);

And it is the nature of a matrix transformation that it is applied to the whole image, so if you only want to use a part of a DC, you have to "cut" that part for this purpose.
0
 
WxWAuthor Commented:
Hi.
Thanks for helping me, but the code doesn't work.

It still rotates around 0,0.

see http://www.turboirc.com/temp/fig1.jpg (normal)
see http://www.turboirc.com/temp/fig2.jpg (rotated)

0
 
jkrCommented:
Soory, try

graphics.TranslateTransform( 0 - (rc.right - rc.left)/2 , 0 - (rc.bottom - rc.top)/2, MatrixOrderPrepend);

before rotating.
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
WxWAuthor Commented:
Now the result is
http://www.turboirc.com/temp/fig3.jpg
after 5 degrees rotating.

0
 
jkrCommented:
You should move the picture back to its original position after the rotation.
0
 
WxWAuthor Commented:
Let me read the wikipedia article u posted for transformations and after I know more on the subject I will let you know.
0
 
WxWAuthor Commented:
Thanks to your solution, I am now able to understand the concepts of Transformation and I understood how GDI+ implements it , and it now works.

Best Regards,
Michael.
0
 
jkrCommented:
You're most welcome. I was more than 'fluent' on that stuff ~15 yrs ago, nice to now that some things last ;o)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now