rotate image x degrees lazarus / 39-Graphics ---------------------------------------------------------------------- picstart · 2012-08-18 19:10 What is the best way to rotate an image a given number of degrees? Ex. a compass rose loaded from a bmp into Timage.........needs to rotate  to have heading direction toward top of the screen......if the direction was SSE then SSE would be the at the top. Win7 pro 32 lazarus 1.0RC1 ---------------------------------------------------------------------- marcov · 2012-08-18 19:22 The general case is more expensive than n* 90 degrees. That latter case (n*90 degrees) I researched thoroughly, see http://stackoverflow.com/questions/848025/rotating-bitmaps-in-code ---------------------------------------------------------------------- picstart · 2012-08-18 21:12 Well,  90 deg transform doesn't fit the heads up compass requirement. The magnetometer takes several dozens of milli seconds to settle so speed isn't critical. I did a web search and there are API's SetWorldTransform()  XFORM type transforms for other languages that do the rotational transform and interpolate to the nearest pixel..I was hoping lazarus might have something as well. ---------------------------------------------------------------------- User137 · 2012-08-19 12:19 Does something like BGRABitmap do the thing you are after? Then again if you're planning a full blown graphical game, i can hint about my OpenGL based game engine http://code.google.com/p/nxpascal/ Code: [Select]procedure DrawRotateS(x,y: single; pattern: word; a,cx,cy, sizeX,sizeY: single);This can draw like 10000 big about fullscreen sized images in fraction of second. Rotate with n% degrees, colored, transluscent, scaled, rotation centered on any point of the image and so forth. Also it accepts patterns for animation, for example you can have several animation frames in same image. ---------------------------------------------------------------------- circular · 2012-08-19 13:21 If you don't need intensive drawing, you can use BGRABitmap. Here is a sample project, using BGRAControls and BGRABitmap : ---------------------------------------------------------------------- circular · 2012-08-19 13:23 It uses PutImageAngle function on a TBGRAGraphicControl. Here is how it looks like : ---------------------------------------------------------------------- picstart · 2012-08-19 16:11 Thank you circular I spent several hours getting 'SetWorldTransform' and TXForm working within the windows unit. I use BGRA alot but thought it only did 90 deg at a time rotations. Often a wrong assumption leads to a diversion..I did get TXForm to rotate  the compass rose but BGRA is my favorite so I'll recode to BGRA. Oh and kudo's the quality code you supplied actually worked out of the box so thanks for testing it before posting it. What's more it is infinitely better than the convoluted code I have for 'SetWorldTransform' and TXForm . ---------------------------------------------------------------------- circular · 2012-08-19 17:12 You're welcome. ---------------------------------------------------------------------- circular · 2012-08-19 17:46 If for some reason you need to play with transforms, you can use Canvas2D property of BGRABitmap, which works like the HTML canvas. There you have "rotate", "translate" etc. But I also prefer functions like PutImageAngle or PutImageAffine. It's sufficient in most cases.