更新时间:2023-09-11 09:05:46
如果将所有框架,形状和图片放在新的TPanel(我的样品中名为MainPanel)中,则可以使用:
procedure savePanelAsImage(fpPanel:tPanel; fpFileName:string);
var
img:TBitmap;
begin
img:= TBitmap.Create;
try
img.Width:= fpPanel.Width;
img.Height:= fpPanel.Height;
fpPanel.PaintTo(img.Canvas,0,0);
img.SaveToFile(fpFileName);
finally
img.Free;
end
end;
用法:
savePanelAsImage(MainPanel,'d:\someFolder\image001.bmp');
注意:
为了更好的结果/灵活性,我建议使用用于Delphi的Graphics32 库(它支持图层,图像重新调整尺寸等)。
This is what I need: Program for quicker making fun posters for facebook page. Posters have text, picture and frame (white line and black background). In this case, I want to insert logo on poster (png image).
Depending on picture size, dimensions of frame (who in this case consits of two shapes) must automaticly be resized for picture.
How to save poster from that image from link (2 shape components, 2 image components, 2 labels) as picture?
How to accomplish this? What to use, where to begin?
I hope that this question will not be removed.
If you put all the frames, shapes and pictures inside a new TPanel (named MainPanel in my sample), then you could use:
procedure savePanelAsImage(fpPanel: tPanel; fpFileName: string);
var
img: TBitmap;
begin
img := TBitmap.Create;
try
img.Width := fpPanel.Width;
img.Height := fpPanel.Height;
fpPanel.PaintTo(img.Canvas, 0, 0);
img.SaveToFile(fpFileName);
finally
img.Free;
end
end;
Usage:
savePanelAsImage(MainPanel, 'd:\someFolder\image001.bmp');
Notes:
For better results / flexibility I would suggest using Graphics32 library for Delphi (it supports layers, image re-sizing etc.).