Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying TImage.picture and TImage.canvas simultaneously

Status
Not open for further replies.

Naktibalda

Programmer
Aug 28, 2010
4
US
This is more of a theoretical question. I have a program which displays complex vascular networks. The vessels are drawn as polygons in a TImage canvas. I would now like to load and display a bitmap image behind the canvas. When I try to load an image to the TImage.picture, all the objects on the canvas disappear. Additionally, if I load a picture and then draw my objects onto the canvas, the picture disappears. It seems that these two objects (the canvas and picture) override each other.

I've had some luck using a separate image for displaying the picture, which is located behind the image used for displaying the vessels, however there are problems with this approach as well. To use this method the image on which the vessels are drawn must be transparent. This causes all sorts of flickering when redrawing. I've tried all the normal remedies for flickering (double buffering etc) but nothing really works. When the image is opaque, there is no problem with flickering.

So my question is, can canvases and pictures be used in conjunction? And if not, what alternatives could I use to display polygons and bitmaps together?


Any advice is appreciated, thanks.
 
It seems that these two objects (the canvas and picture) override each other.

Not exactly. TImage.Canvas is a drawn representation of the image, which might be represented in any of the image forms represented by TPicture. Draw on the canvas, it shows on the screen, load a picture, it's reflected on the canvas. It's best to think of TImage as a generic picture holder.

This causes all sorts of flickering when redrawing.

The problem is you're pumping data through VCL controls which require update and redraw. This takes a little time. Play with using small amounts of sleep (like 20-50ms), and Application.ProcessMessages. Though there are better ways than trying to link multiple VCL controls.

So my question is, can canvases and pictures be used in conjunction?

Not in TImage.

And if not, what alternatives could I use to display polygons and bitmaps together?

Lay the Bitmap onto one Canvas and then draw your polygons to another canvas and then copy the polygons to the other canvas, ignoring whatever your background color is. You'll have to play with the settings, specifically TCanvas.CopyMode. You can achieve any multiple effect you want if you get the right patterns/settings down.

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.
 
I happened on this post by chance. Thank you this was a problem I encountered a while ago (the flickering) and now I know why and how to handle it.

Thanks Glenn and Naktibalda !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top