如何添加相框并在图像中插入文字? [英] How to add a picture frame and insert the text in the image?

查看:411
本文介绍了如何添加相框并在图像中插入文字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我需要的:为更快的为facebook页面制作乐趣海报的节目。
海报有文字,图片和框架(白线和黑色背景)。
在这种情况下,我想在海报上插入徽标(png图像)。



根据图片大小,框架尺寸(在这种情况下属于两个形状)必须自动调整大小。





如何从链接(2个形状组件,2个图像组件,2个标签)中保存该图像的海报作为图片?



如何完成这个?使用什么,从哪里开始?



我希望这个问题不会被删除。

解决方案

如果将所有框架,形状和图片放在新的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;

用法:



pre> savePanelAsImage(MainPanel,'d:\someFolder\image001.bmp');

注意:




  • 这是基于VCL的示例;

  • 要以其他格式(而不是BMP)保存图像,请使用:TPngImage(Vcl.Imaging.pngImage)或TJPEGImage(Vcl.Imaging.jpeg);

  • 如果您使用FireMonkey(> = Delphi XE2),您可以利用someParentComponent.MakeScreenShot();

  • 生成的图像的大小与tPanel相同。



为了更好的结果/灵活性,我建议使用用于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:

  • 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.).

这篇关于如何添加相框并在图像中插入文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆