How can you draw an image with an affine transformation applied in FireMonkey? I would like to take a rectangular bitmap, and draw that (in a 2D form) stretched to a not-quite-arbitrary four-sided polygon, the corner points of which I calculate. It happens that the polygon will result in a shape that could be implemented via a simple affine transformation. I hoped for a way to use TCanvas.Matrix to achieve this, or for a Draw method that took a target polygon instead of a rectangle, or to be able to use TImage3D in a 2D form, or something similar. I can't find one. Any ideas?

How can you draw an image with an affine transformation applied in FireMonkey?  I would like to take a rectangular bitmap, and draw that (in a 2D form) stretched to a not-quite-arbitrary four-sided polygon, the corner points of which I calculate. It happens that the polygon will result in a shape that could be implemented via a simple affine transformation. I hoped for a way to use TCanvas.Matrix to achieve this, or for a Draw method that took a target polygon instead of a rectangle, or to be able to use TImage3D in a 2D form, or something similar.  I can't find one. Any ideas?

I'm aware of TAffineTransformEffect but can't see how to go from the four quad points to the rotation/scale values it requires (and it seems to give different results in XE6 than the screenshots in the documentation.)

Any ideas?

#fmx   #firemonkey  #transformation #affine

Comments

  1. This is possible in GDI if I recall correctly using an "xform". Would be weird (but not that) surprising if it's missing in FireMonkey.

    ReplyDelete
  2. Asbjørn Heid Yes, and I've done it there once or twice. I suppose it is "advanced" drawing, but it's very useful. Any ideas how to hack it into FMX, perhaps?

    ReplyDelete
  3. David Millington I haven't used FMX but reading the doc's, using TCanvas.SetMatrix should work. At least it calls Direct2D's ID2D1RenderTarget.SetTransform method if you got a TCanvasD2D instance, which looks like what you want.

    Then use TCanvas.DrawBitmap. Worth a shot I guess :)

    ReplyDelete

Post a Comment