Solved

Draw text transparently on a canvas

Posted on 2001-06-11
7
406 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
Comment Utility
Hi duke_n,
did you try  Canvas.Brush.Style = bsClear?

-----
Igor.
0
 
LVL 1

Author Comment

by:duke_n
Comment Utility
My man you are a genius!

now what about the second problem?
0
 
LVL 1

Author Comment

by:duke_n
Comment Utility
ah, I found what I meant.

to set Canvas.Pen.Mode:=pmNot;

but it doesn't seem to affect the font.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 9

Accepted Solution

by:
ITugay earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you very much.

You have been of great help
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now