Jump to content
Sign in to follow this  
XylemFlow

Group a collection of drawn objects to have a single opacity

Recommended Posts

I need to be able to draw several objects to a form or TImage TCanvas, including lines, circles, polygons, text, etc and have them drawn as a group with a single opacity. If I draw them separately then it won't look correct where they overlap.

I currently do this by drawing the objects to an offscreen TBitmap canvas with full opacity and then drawing the TBitmap to my form or TImage TCanvas with the opacity I want. However, this is slower and uses more memory. I'd also like to use Skia in future, but I understand that drawing to offscreen bitmaps is slower since it doesn't use the GPU.

Is there a method to group objects in this way in default FMX or Skia without using an offscreen bitmap? 

Share this post


Link to post

You can add all objects to the same TLayout and then control the opacity from this TLayout.

Share this post


Link to post

All objects under same layout and managing layers and groups with TLayout: Yes, definitively.


Not sure what kind of "opacity" you need, but you could also put finally a TRectangle as cover over all, with Align := Contents,

and set HitTest := False, Stroke.Kind := None,  File.Color := White (or Black depending on your design), and set Opacity as you desire.
This will "grey out" the underlying objects, while they are still active.

 

Share this post


Link to post

Unfortunately I need to draw everything directly on a single TCanvas. I cannot do it by layering controls on top of each other. One reason is because I need to export the resulting image. By sharing the same opacity I mean that they should be semi transparent and so show previously drawn objects underneath

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×