VB6 - GDIPLUS: how rotate an image on center?

This topic is 658 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

how can i rotate an image on it's center?

Dim i As Integer
For i = 0 To 360
GdipTranslateWorldTransform hGraphics, 100, 100, MatrixOrderAppend
GdipRotateWorldTransform hGraphics, 45!, MatrixOrderPrepend
GdipTranslateWorldTransform hGraphics, -100, -100, MatrixOrderAppend
GdipDrawImageRectRect hGraphics, HBITMAP, 100, 100, lngwidth, lngheight, 0, 0, lngwidth, lngheight, UnitPixel, ImageAttributes
Sleep 500
Next


that code can draw the image rotated. but it's drawed on several positions instead on it's center :(

Share on other sites

Never done VB6 or GDIPLUS, but the normal trick is to first translate the center of the image to the origin, then rotate, then translate back to were it was.

(Rotation rotates around origin, so if your image is not there, it moves.)

Share on other sites
Is this happening because it's not erasing the old image?

Because it's not erasing, you get several of the image rotated around a pivot point.

On an important side note is there a legitimate reason you are using vb6, which hasnt been supported by Microsoft for decades, when there are better free options like visual studio community 2015?

Share on other sites

the image is drawed in a circle way. but not on same position :(

Share on other sites

Why are you translating to (100,100)? You first need to translate to the origin (0,0), rotate and then translate back to the original position. Rotation is based around (0,0) unless the math library does some really weird and unexpected work in the background.

 Is the initial position at (-100,-100)? That's the only way I can make sense of this.

Edited by MarkS

Share on other sites

i'm trying from what i have seen :(

but like you see, isn't correct :(

the image position is changed too :(

Share on other sites
The image is rotating, just around a pivot near the top left of the window rather than the centre of the image.

What are the actual image dimensions, and could this be related to the 100,100 in your code above?

i don't know

Share on other sites
Is the code from a tutorial, is there a url to it so we can see the code in context?

Share on other sites

i'm sorry... the 100X100 is the position where i must draw the image. so the 1st image is drawed on correct position. the next image isn't.

i'm trying learning, from several places, how use the rotate. but seems so complicate without understand it :(

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 13
• 59
• 11
• 10
• 14
• Forum Statistics

• Total Topics
632967
• Total Posts
3009559
• Who's Online (See full list)

There are no registered users currently online

×