Home > Back-end >  How to output label into BMP or JPG
How to output label into BMP or JPG

Time:10-06

Want to turn the letters on the label into image output

CodePudding user response:

Seems there is no direct function,
Can obtain the location of the label with size, put a piece of cut into the image

CodePudding user response:

 
Var
Cc: TControlCanvas;
BMP: TBitmap;
The begin
BMP:=TBitmap. Create;
Cc:=TControlCanvas. Create;
Try
Cc. Control:=Label1;
BMP. Width:=cc. Control. Width;
BMP. Height:=cc. Control. Height;
BitBlt (BMP. Canvas. Handle, 0, 0,
BMP. Width, BMP. Height, cc. Handle, 0, 0, SRCCOPY);
BMP. SaveToFile (' c: \ test. BMP);
The finally
Cc. Free;
BMP. Free;
end;
end;

CodePudding user response:

Sololie super severe,
This code from seemingly meaningless,

I was to write not to come out,
Finally even written, is also checked several web pages, repeatedly changed N times,
Too much too much

CodePudding user response:

So he is a cow people...

CodePudding user response:

refer to the second floor sololie response:
 
Var
Cc: TControlCanvas;
BMP: TBitmap;
The begin
BMP:=TBitmap. Create;
Cc:=TControlCanvas. Create;
Try
Cc. Control:=Label1;
BMP. Width:=cc. Control. Width;
BMP. Height:=cc. Control. Height;
BitBlt (BMP. Canvas. Handle, 0, 0,
BMP. Width, BMP. Height, cc. Handle, 0, 0, SRCCOPY);
BMP. SaveToFile (' c: \ test. BMP);
The finally
Cc. Free;
BMP. Free;
end;
end;

Very cow, is very correct

CodePudding user response:

 var 
BMP: TBitmap;
The begin
BMP:=TBitmap. Create;
Try
With lbl1 do
The begin
BMP. Width:=Width;
BMP. Height:=Height;
BMP. Canvas. CopyRect (ClientRect, Canvas, ClientRect);
BMP. SaveToFile (' c: \ aa. BMP);
end;
The finally
BMP. Free;
end;
end;

CodePudding user response:

refer to the second floor sololie response:
 
Var
Cc: TControlCanvas;
BMP: TBitmap;
The begin
BMP:=TBitmap. Create;
Cc:=TControlCanvas. Create;
Try
Cc. Control:=Label1;
BMP. Width:=cc. Control. Width;
BMP. Height:=cc. Control. Height;
BitBlt (BMP. Canvas. Handle, 0, 0,
BMP. Width, BMP. Height, cc. Handle, 0, 0, SRCCOPY);
BMP. SaveToFile (' c: \ test. BMP);
The finally
Cc. Free;
BMP. Free;
end;
end;

DELPHI master!
  • Related