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!

How to draw over Image->Picture upon FormPaint()

Status
Not open for further replies.

HuntsvilleRob

Programmer
Nov 3, 2010
26
US
Hello.
I have a TImage on my form, Image1. I have loaded a picture onto it via
Image1->Picture->LoadFromFile(FileName);

Now I draw some lines on the form by calling the TForm1::FormPaint(TObject* Sender) method. I'm drawing these lines across the Image1 object. The lines display fine. But now when I minimize the form or move another window on top of it and then go back to my form, the image is there but the lines are *behind* it. Looks like when I minimize the window, the FormPaint is called first and then the Image1->Picture is draw over it. Can't figure out how to call the FormPaint method *after* the Image1 refreshes. I appreciate your help!

-Rob
 
OK, I have found that to draw on a TImage on my form, I can do

Image1->Canvas->Pen->Color = clRed;
Image1->Canvas->MoveTo(10, 10);
Image1->Canvas->LineTo(10, 60);

in TForm1::FormPaint and as long as I set the Image1 property Stretch to be true, it will draw to above line and not flicker like crazy. If I'm trying to draw this red line on a black and white image that was loaded into Image1 via

Image1->Picture->LoadFromFile(Filename);

the red line will be black, regardless of statement above which is supposed to set the pen to draw red. In fact, all the lines drawn on the image will be black, regardless of what you set the pen. I wish to be able to draw with colors on the b&w image. What am I not doing? Thanks.
 
Check the PixelFormat:
Code:
Image1->Picture->Bitmap->PixelFormat;

That may not have anything to do with the fact Image1 is not displaying red lines. Your ..Pen->Color, MoveTo, and LineTo code is correct and should draw straight clRed lines.

If you need a grayscale image on which to do some math and at the same time you need to draw on the grayscale image, you can open the file using Graphics::TBitmap and then draw the TBitmap onto TImage so you will have two copies of the data. I do this in a program I use to 'measure' component temperatures based on a thermal imager scan.

Steve.
 
Hey, Steve.
Thanks very much for the help. I looked at the PixelFormat; it was set to the default which is pfDevice. I changed it to pf24bit and voila, colored lines!
I exactly do as you do, i.e., open one image to do the math and another for the image.
One other thing maybe you can help with, please. The FormPaint function does the line drawing on the Image1. It does that fine now but when I move another window in front of it and then move it back (or when I minimize the window and then restore it), the lines on the Image1 are there (in color now, thanks) but the other components are not redrawn, e.g. the buttons and group boxes. I have to grab the window at the top and move it to get the components to redraw. Any ideas how to fix this? Thanks.

-Rob
 
No, I am afraid I do not know how to cause TForm to refresh/repaint itself when a window above it is moved/minimized. I have seen similar behavior in other programs.


I know where a handful of people who are experts at using Builder for graphics applications 'hang out':

Perhaps you can post some of this question there. There you will also find a link to answers to commonly asked questions.


Steve.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top