Solved

Putting text on an image?

Posted on 1998-05-31
10
296 Views
Last Modified: 2010-04-06
I can get text onto an image. But I want to label any edits that I make but when I try to go to another edit and label it the previous label disapears. Can anyone help please?

Here is the code I am Using.

procedure TMapEditor.Image1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
if Button = mbLeft then
begin
textdialog.showmodal;
Mapeditor.Canvas.TextOut(x,y, textdialog.edit1.text);
end;
end;
0
Comment
Question by:mykyl
  • 6
  • 4
10 Comments
 
LVL 1

Expert Comment

by:Edo082297
Comment Utility
Hello Mykyl,
  What exactly are you trying to do? How do you want to label edits? What is the purpose of textdialog? It will pop up every time there is a mouse up. Then, if MapEditor is your form, the text may be covered by the image. I tried a project with your code, it works fine for me. What is the problem?
0
 

Author Comment

by:mykyl
Comment Utility
Ill try to explain.
I have an image of a map on screen. I click on any point on the image and a small marker circle appears on the image at this point on mouseclickup a dialog box opens up for the user to enter text to label the circle. This works so far. Now I want to click on another point on the image I mouseclickdown the marker circle appears but the previous labelled marker circle's label disappears. What I want to do is label all marker circles as I go along.
I hope you can understand what Im asking and can help.
Thank you.
0
 
LVL 1

Expert Comment

by:Edo082297
Comment Utility
Hi Mykyl,

  Your problem lies elsewhere. Step back from the project and try to find other causes. The code you supplied works perfectly in conjunction with the events you are using:

procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  textdialog.showmodal;
  Image1.Canvas.TextOut(X, Y, textdialog.edit1.text);
end;

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  Image1.Canvas.Ellipse(X, Y, (X+50), (Y+50));
end;

  This code works, it does just what you want. Show me what you are doing OnMouseDown, you have probably made a small error there.

Edo

0
 

Author Comment

by:mykyl
Comment Utility
Here is the code for mouse down.

procedure TMapEditor.Image1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
Clipboard.Assign(Image1.Picture);{make a copy for undo}
  if Button = mbLeft then
  begin
    if ssShift in Shift then
      Image1.Canvas.Rectangle (X-Radius, Y-Radius,
        X+Radius, Y+Radius)
    else
      Image1.Canvas.Ellipse (X-Radius, Y-Radius,
        X+Radius, Y+Radius);
    Changed := True;
  end;
end;
0
 
LVL 1

Expert Comment

by:Edo082297
Comment Utility
Hi Mykyl,

Here is what I tested:

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  Clipboard.Assign(Image1.Picture);

  if Button = mbLeft then
    Image1.Canvas.Ellipse (X-Radius, Y-Radius, X+Radius, Y+Radius);

end;

  I have had no problems with this code. Your problem is generated from somewhere else. Trace into the code, because something else is preventing the label from staying where it should. I have to go now (2pm eastern time GMT - 5) but would like to help you out. If I were you, I would create a new application for the purposes of debugging what you have. Add the code we have here, and make sure it works. Then, add one element at a time of what you have, and keep testing. You should find the problem this way. Just use any bitmap, and keep your testing code as simple as possible, while maintaining a parallel with what you are attempting to do. If that doesn't appeal to you, put on your hunting hat, and trace into what you've got. Set breakpoints where you expect the code to go and check your values.

I will check out your progress around 9 pm.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:mykyl
Comment Utility
Im almost too embarrased to tell you what was wrong.

Mapeditor.Canvas.TextOut(x,y, textdialog.edit1.text); is what I was putting but It should have been

IMAGE1.Canvas.TextOut(x,y, textdialog.edit1.text);

What an idiot Ive Been. I couldnt see the wood for the trees as they say here.
Any way Is there a way to get the label to have an invisible background so that only text is showing up not text with a border.
Thank you.
It does not matter if you cant or dont want to answer this bit as Ill send you the points anyway.
Mike

0
 
LVL 1

Expert Comment

by:Edo082297
Comment Utility
Hi Mike,
  I have programmed a fair amount, and let me tell you that seeing the wood for the trees is a MAJOR source of bugs. You would laugh at bugs that I and co-workers have had. Yes, sometimes you just want to hit yourself. Just remember, when you have a bug like this (i.e. not a 'flow of logic' (flaw of logic!) style of bug), the best thing to do (at least for me) is to take a coffee break(!). Don't think about your bug. After a minimum of 10 minutes, go back and scrutinize each line of code, especially where 'the action' should be taking place. It's a way of increasing your scope. I think of it like horses running a race. They wear blinders towards their goal, and sometimes as programmers looking at specifics wear them too. The trick is knowing how to take them off. Another good technique is having fresh eyes: get a friend to look at what you are doing. Explain each line of your code to them. You will be amazed to see how often a friend can spot the problem area! Anyway, enough rambling from this peanut gallery.
  So... you want a label with a 'clear' background. Well, that's not such a tall order, but it will require more than just setting a property. In fact, what we should do is create a customized label. Specifically, we should derive a new component from TCustomLabel and override the paint method. Then, in MapEditor (Image1, I mean ;) ) we should create instances of this new type and place them at the given x and y coordinates. The other benefit of creating our own component is that we might be able to include some other helpful behaviour and encapsulate it within our new control.  I will try and make the clear label for tomorrow. You should think about what else the label might need as extra behavior. What exactly is the label labelling? Is there anything else that would be cool for the label to be able (gotta love the alliteration) to do?

Regards,

Edo
0
 
LVL 1

Accepted Solution

by:
Edo082297 earned 70 total points
Comment Utility
Guess what, Mike!
 
  I didn't see the wood for the trees. Atleast, sort of. I took another look at TLabel, and lo and behold, there is a transparent property. So, setting it to true does what we want, and avoids creating a new component (unless there is some other reason to do so). Instead of asking windows to draw the text for us, we are now going to drop labels on the form:

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  ALabel : TLabel;
begin
  Clipboard.Assign(Image1.Picture);

  if Button = mbLeft then
  begin
    Image1.Canvas.Ellipse(X, Y, X+10, Y+10);

    ALabel := TLabel.Create(Self);

    with ALabel do
    begin
      Parent := Self;
      Transparent := True;
      Left := X;
      Top := Y;
      Font.Style := [fsBold]; // for better visibility
    end;
   
    // separate this special part from our preceding statements
    TextDialog.ShowModal;
    ALabel.Caption := TextDialog.Edit1.Text;

  end;
end;

Note that I have put the code from the mouse up and down together in one shot. The visual effect is not changed (you can see the dot before the text is applied). I trust you know everything that is going on here. The only curve ball in the above code is the Parent := Self; statement. The parent property is the WinControl (panels, group boxes, forms etc...) that will display the created control. This is not to be confused with the Owner, who is responsible for destroying the control (and is the parameter that is passed to the constructor).

Best of luck, Mike, and please drop me a note if you have more stuff you want to do.

Edo
0
 

Author Comment

by:mykyl
Comment Utility
The label I was meaning is the text label on the image. At the moment after putting the circle marker and entering the text the background of the text is the same colour as the circle. I would prefer it to be transparent.

Any ideas??

Thank you
Mike
0
 
LVL 1

Expert Comment

by:Edo082297
Comment Utility
Hi Mike,
  Thanks for the points.
  If you want to control more closely the color of the text, just change the Label.Color to be the same. I would also suggest using a TShape instead of letting Windows paint for you. This means that you can access the color by means of Shape.Brush.Color. And, you'll have access to the object later later on: you might change the color or respond to click events.... I think that using TShape and TLabel is the way to go. That way it will be something you can do stuff with, and not be just a mark on your canvas. Did you know you can even drag them? Check out the properties of both objects and let your imagination run wild!
  Have fun, and let me know how you are doing. We can communicate through this thread, or through egarson@hotmail.com if you prefer.

Edo
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now