Solved

Draw text transparently on a canvas

Posted on 2001-06-11
7
411 Views
Last Modified: 2011-09-20
I need to draw a text on a canvas.
Here are the problems:

1)TextOut draws a frame behind the text(like does a fillrect first and then draws the text over the rect). I only need to draw the text. I tried to make Canvas.Brush.Color:=clNone but that only made it white.

2)for the text to be seen without the mentioned frame, its colour should be the invert of the area around it. I remember this is done somehow with NOT operator, but I don't exatcly remember how.
0
Comment
Question by:duke_n
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 9

Expert Comment

by:ITugay
ID: 6177099
Hi duke_n,
did you try  Canvas.Brush.Style = bsClear?

-----
Igor.
0
 
LVL 1

Author Comment

by:duke_n
ID: 6177215
My man you are a genius!

now what about the second problem?
0
 
LVL 1

Author Comment

by:duke_n
ID: 6177255
ah, I found what I meant.

to set Canvas.Pen.Mode:=pmNot;

but it doesn't seem to affect the font.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Accepted Solution

by:
ITugay earned 100 total points
ID: 6177304
Hi duke_n,
I'm not sure how to draw font directly using XOR or something like this. But you can try to draw it in memory bitmap and then use BitBlt API function to copy region to canvas you need.  BitBlt supports lot of raster operations codes, just take a look at Delphi's help.

-----
Igor.
0
 
LVL 1

Author Comment

by:duke_n
ID: 6178266
this is really weird. I used this function many many times, but now nothing works:

var
BMp:TBitMap;
s:string;
pt:TPoint;
begin
  s:='Show me the  money' ;
  BMP:=TBitmap.Create;
  BMP.Width:=Canvas.TextWidth(s);
  BMP.Height:=Canvas.TextHeight(S) ;
  bmp.Canvas.Brush.Style:=bsClear;
  BMP.Canvas.TextOut(0,0,s);
  PT.x:=200;
  Pt.y:=50;
  Pt:=Image1.ClientToScreen(PT);
  if INteger(BitBlt(Image1.{Picture.Bitmap.}Canvas.Handle,Pt.x,Pt.y,BMP.Width,BMP.Height,BMP.Canvas.Handle,0,0,SRCERASE))<>0 then
    ShowMessage('Success');
  bmp.Free;


The weirdest thing is that it shows "Success" but it doesn't change the canvas.
0
 
LVL 1

Author Comment

by:duke_n
ID: 6178355
HAHA, Got it


var
BMp:TBitMap;
s:string;
pt:TPoint;
begin
  s:='Show me the  money' ;
  BMP:=TBitmap.Create;
  BMP.Width:=Canvas.TextWidth(s);
  BMP.Height:=Canvas.TextHeight(S) ;
  bmp.Canvas.Brush.Style:=bsClear;
  BMP.Canvas.TextOut(0,0,s);
  Image1.Picture.Bitmap.Width:=Image1.Width;
  Image1.Picture.Bitmap.Height:=Image1.Width;
  PT.x:=200;
  Pt.y:=80;

  if INteger(BitBlt(Image1.Picture.Bitmap.Canvas.Handle,Pt.x,Pt.y,BMP.Width,BMP.Height,BMP.Canvas.Handle,0,0,SRCINVERT))<>0 then
    ShowMessage('Success');

  InvertRect(Image1.Picture.Bitmap.Canvas.Handle,RECT(Pt.x,Pt.y,Pt.x+BMP.Width,Pt.y+BMP.Height));
  bmp.Free;

end;
0
 
LVL 1

Author Comment

by:duke_n
ID: 6178390
Thank you very much.

You have been of great help
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

752 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