Solved

Draw text transparently on a canvas

Posted on 2001-06-11
7
410 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
  • 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 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