Solved

Save Label as Image/Picture

Posted on 2006-10-28
6
236 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

828 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