Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Draw text transparently on a canvas

Posted on 2001-06-11
7
Medium Priority
?
414 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 400 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

721 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