Link to home
Start Free TrialLog in
Avatar of duke_n
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.
Avatar of Igor UL7AAjr
Igor UL7AAjr
Flag of Kazakhstan image

Hi duke_n,
did you try  Canvas.Brush.Style = bsClear?

-----
Igor.
Avatar of duke_n
duke_n

ASKER

My man you are a genius!

now what about the second problem?
Avatar of duke_n

ASKER

ah, I found what I meant.

to set Canvas.Pen.Mode:=pmNot;

but it doesn't seem to affect the font.
ASKER CERTIFIED SOLUTION
Avatar of Igor UL7AAjr
Igor UL7AAjr
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of duke_n

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.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.
Avatar of duke_n

ASKER

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;
Avatar of duke_n

ASKER

Thank you very much.

You have been of great help