Jump to content

How to rotate a Bitmap by it's center

Recommended Posts

Does any body knows how to rotate a bitmap by it's center via GDI+... I have been testing with

Graphics.RotateTransform() & Graphics.TranslateTransform() but haven't got the desired effect... Rotate transform does rotate the image but from origin at the left top pixel... I need it to rotate from the center of the bitmap... does anybody knows how to do it?

Link to post

Rotate & TranslateTransform don't rotate the pixels, but the coordinate system.

Its like moving the paper before drawing normally.

So, translate first to picture.width/2 height/2, then rotate, then draw.



Link to post

Thanks herd.... but I quite do not get it... I am doing something like this:

Gdiplus::Bitmap *numberBitmap = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Bitmap(max, max, PixelFormat32bppARGB);
Gdiplus::Graphics numberGraphics(numberBitmap);
Gdiplus::GraphicsPath numberPath(FillModeAlternate);

Rect numberRect(0, 0, rectSize.Width+1, rectSize.Height+1);

numberGraphics.TranslateTransform(max/2, max/2);
[SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// Draw the backgrounf that encloses the text.
numberGraphics.FillRectangle(&white, numberRect);
numberPath.AddString(text, -1, &fontFamily, style, size, numberRect, &format);
[SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// Draw a rectangle that encloses the text.
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]numberGraphics.DrawRectangle(&penColor, numberRect);
[SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// Draw the text
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]numberGraphics.FillPath(&fontColor, &numberPath);

but the image I am getting is not what I expected... it is something like this (error1.png), if I exchage the transofrm & rotate I get the second image (error2.png).

So I am not sure what am I doing wrong here.



Link to post

Please sign in to comment

You will be able to leave a comment after signing in

Sign In Now
  • Create New...