2

How can I rotate a png image in Delphi with preserving its transparency? I loaded it via TPNGObject. I'm then using Canvas.StretchDraw(MyRect, the TPNGObject) but I don't know how to rotate it.

Heinrich Ulbricht
  • 10,064
  • 4
  • 54
  • 85
Sara S.
  • 1,365
  • 1
  • 15
  • 33
  • 3
    I haven't used it for rotation, but you might try the freeware at www.graphics32.org if you don't get a better answer here. – RobertFrank Nov 22 '11 at 15:26
  • 1
    I suspect this will be slow and painful in VCL, slow and easy in graphics32 + VCL, and fast and easy in Firemonkey (FMX) in XE2. – Warren P Nov 22 '11 at 17:41
  • 1
    Following the link in [this answer](http://stackoverflow.com/questions/2437714/resize-png-image/2439466#2439466) will lead to example code. – Sertac Akyuz Nov 22 '11 at 18:44

1 Answers1

4

The problem is that if you do a rotate using the Canvas, you will lose your transparency, as you noted with TPNGObject.

This is because the Canvas doesn't support transparency at the level required by a PNG image.

Instead, you must use specialized code to rotate the PNG image. Here is a link to a library of code that supports the TPNGObject, including a function to rotate it: http://cc.embarcadero.com/Item/25631

Marcus Adams
  • 53,009
  • 9
  • 91
  • 143
  • Thanks Marcus so much ..but do you have any idea how to fasten this code because he uses a for loop over the width and height. – Sara S. Nov 24 '11 at 07:59