duke_n
asked on
Draw text transparently on a canvas
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.
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
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.
ASKER
My man you are a genius!
now what about the second problem?
now what about the second problem?
ASKER
ah, I found what I meant.
to set Canvas.Pen.Mode:=pmNot;
but it doesn't seem to affect the font.
to set Canvas.Pen.Mode:=pmNot;
but it doesn't seem to affect the font.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.TextWidt h(s);
BMP.Height:=Canvas.TextHei ght(S) ;
bmp.Canvas.Brush.Style:=bs Clear;
BMP.Canvas.TextOut(0,0,s);
PT.x:=200;
Pt.y:=50;
Pt:=Image1.ClientToScreen( PT);
if INteger(BitBlt(Image1.{Pic ture.Bitma p.}Canvas. Handle,Pt. x,Pt.y,BMP .Width,BMP .Height,BM P.Canvas.H andle,0,0, SRCERASE)) <>0 then
ShowMessage('Success');
bmp.Free;
The weirdest thing is that it shows "Success" but it doesn't change the canvas.
var
BMp:TBitMap;
s:string;
pt:TPoint;
begin
s:='Show me the money' ;
BMP:=TBitmap.Create;
BMP.Width:=Canvas.TextWidt
BMP.Height:=Canvas.TextHei
bmp.Canvas.Brush.Style:=bs
BMP.Canvas.TextOut(0,0,s);
PT.x:=200;
Pt.y:=50;
Pt:=Image1.ClientToScreen(
if INteger(BitBlt(Image1.{Pic
ShowMessage('Success');
bmp.Free;
The weirdest thing is that it shows "Success" but it doesn't change the canvas.
ASKER
HAHA, Got it
var
BMp:TBitMap;
s:string;
pt:TPoint;
begin
s:='Show me the money' ;
BMP:=TBitmap.Create;
BMP.Width:=Canvas.TextWidt h(s);
BMP.Height:=Canvas.TextHei ght(S) ;
bmp.Canvas.Brush.Style:=bs Clear;
BMP.Canvas.TextOut(0,0,s);
Image1.Picture.Bitmap.Widt h:=Image1. Width;
Image1.Picture.Bitmap.Heig ht:=Image1 .Width;
PT.x:=200;
Pt.y:=80;
if INteger(BitBlt(Image1.Pict ure.Bitmap .Canvas.Ha ndle,Pt.x, Pt.y,BMP.W idth,BMP.H eight,BMP. Canvas.Han dle,0,0,SR CINVERT))< >0 then
ShowMessage('Success');
InvertRect(Image1.Picture. Bitmap.Can vas.Handle ,RECT(Pt.x ,Pt.y,Pt.x +BMP.Width ,Pt.y+BMP. Height));
bmp.Free;
end;
var
BMp:TBitMap;
s:string;
pt:TPoint;
begin
s:='Show me the money' ;
BMP:=TBitmap.Create;
BMP.Width:=Canvas.TextWidt
BMP.Height:=Canvas.TextHei
bmp.Canvas.Brush.Style:=bs
BMP.Canvas.TextOut(0,0,s);
Image1.Picture.Bitmap.Widt
Image1.Picture.Bitmap.Heig
PT.x:=200;
Pt.y:=80;
if INteger(BitBlt(Image1.Pict
ShowMessage('Success');
InvertRect(Image1.Picture.
bmp.Free;
end;
ASKER
Thank you very much.
You have been of great help
You have been of great help
did you try Canvas.Brush.Style = bsClear?
-----
Igor.