How to add a picture frame and insert the text in the image?

眉间皱痕 提交于 2019-12-05 09:13:06

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:

  • This is VCL based sample;
  • To save the image in other format (rather in BMP) use: TPngImage (Vcl.Imaging.pngImage) or TJPEGImage (Vcl.Imaging.jpeg);
  • If you use FireMonkey (>= Delphi XE2) you can take advantage of someParentComponent.MakeScreenShot();
  • The resulting image will have the same size as the tPanel.

For better results / flexibility I would suggest using Graphics32 library for Delphi (it supports layers, image re-sizing etc.).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!