Solved

Save Label as Image/Picture

Posted on 2006-10-28
6
212 Views
Last Modified: 2010-08-05
Hi to All,

I want to save a Label as an Image or Picture in Bitmap format, please help me.

Thanks in advanced
A.R. Rafiee
0
Comment
Question by:laserayaneh
  • 5
6 Comments
 
LVL 28

Expert Comment

by:TName
ID: 17826831
Hi, to copy the label into a TImage you could try this:

procedure TMainForm.Button1Click(Sender: TObject);
begin
   Image1.Width:=Label1.Width;
   Image1.Height:=Label1.Height;
   BitBlt(Image1.Canvas.Handle, 0, 0, Label1.Width, Label1.Height,
     Label1.Canvas.Handle, 0, 0, SRCCOPY);
end;
0
 
LVL 28

Expert Comment

by:TName
ID: 17826840
To bitmap and then to file:

procedure TMainForm.Button1Click(Sender: TObject);
var
bmp:TBitmap;
begin
   bmp:=TBitmap.Create;
   bmp.Width:=Label1.Width;
   bmp.Height:=Label1.Height;
   BitBlt(bmp.Canvas.Handle, 0, 0, Label1.Width, Label1.Height, Label1.Canvas.Handle, 0, 0, SRCCOPY);
   bmp.SaveToFile('test1.bmp');
end;
0
 
LVL 28

Expert Comment

by:TName
ID: 17826859
oh, and don't forget the

  bmp.Free;

at the end, as I did ;)
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 28

Accepted Solution

by:
TName earned 50 total points
ID: 17826876
Simplified form:

procedure TMainForm.Button1Click(Sender: TObject);
begin
  with TBitmap.Create do begin
      Width:=Label1.Width;
      Height:=Label1.Height;
      BitBlt(Canvas.Handle, 0, 0, Label1.Width, Label1.Height, Label1.Canvas.Handle, 0, 0, SRCCOPY);
      SaveToFile('test1.bmp');
      Free;
   end;
end;
0
 

Author Comment

by:laserayaneh
ID: 17828332
Hi to TName

Thanks you very much 'TName' , your comment is very usefull.

bye...
0
 
LVL 28

Expert Comment

by:TName
ID: 17828366
You're welcome!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

13 Experts available now in Live!

Get 1:1 Help Now