本文介绍了如何制作PNG资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个大的TImage的形式作为背景。问题是,它直接存储在DFM中作为位图,占用大约3 MB。原始的PNG文件是〜250K。我想尝试通过将PNG嵌入资源来减少膨胀,然后在OnCreate中加载表单。我可以这样做,现在Delphi 2009包括PNG支持,除了我不太了解如何使用PNG构建资源文件。任何人知道如何完成?
I've got a form with a large TImage on it as a background. Problem is, this is stored directly in the DFM as a bitmap, which takes up about 3 MB. The original PNG file is ~250K. I'd like to try to reduce bloat by embedding the PNG in a resource, and then having the form load it during OnCreate. I can do that now that Delphi 2009 includes PNG support, except I don't quite know how to build a resource file with a PNG in it. Anyone know how that's done?
推荐答案
示例文本文件(名为myres.rc):
Example text file (named myres.rc):
MYPNG RCDATA mypng.png
已添加项目:
{$R 'myres.res' 'myres.rc'}
在运行时加载的示例:
uses
PngImage;
var
Png: TPngImage;
begin
Png := TPngImage.Create;
try
Png.LoadFromResourceName(HInstance, 'MYPNG');
Image1.Picture.Graphic := Png; // Image1: TImage on the form
finally
Png.Free;
end;
end;
这篇关于如何制作PNG资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!