本文介绍了如何将png图像加载到TImage中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用Delphi XE4将png图像加载到TImage中。 png在流中开始:例如,
I am trying to load a png image into a TImage with Delphi XE4. The png starts off in a stream: E.g.
Stream := TMemoryStream.Create;
try
Stream.LoadFromFile('c:\file.png');
Stream.Position := 0;
Image1.Picture.Graphic.LoadFromStream(Stream);
finally
Stream.Free;
end;
运行此代码时会收到AV。有人可以告诉我我在做什么错吗?
I get an AV when I run this code. Can anyone tell me what I'm doing wrong?
谢谢。
推荐答案
TImage.Picture.Graphic
属性为零,直到将图形加载到 Picture
。
The TImage.Picture.Graphic
property is nil until you load a graphic into the Picture
.
您要的内容可以通过以下方式实现:
What you are asking for can be achieved as follows:
uses pngimage;
Stream := TMemoryStream.Create;
try
// obtain png image, load from file or other..
....
Image := TPngImage.Create;
try
Stream.Position := 0;
Image.LoadFromStream(Stream);
Image1.Picture.Graphic := Image;
finally
Image.Free;
end;
finally
Stream.Free;
end;
这篇关于如何将png图像加载到TImage中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!