Solved

Save Label as Image/Picture

Posted on 2006-10-28
6
224 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
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…

786 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