如何将 BLOB 流中的任意图像加载到 TImage 中? [英] How to load an arbitrary image from a BLOB stream into a TImage?
问题描述
如果我理解正确,TImage.LoadFromFile
根据文件扩展名确定图片类型.
If I understand it correctly, TImage.LoadFromFile
determines the type of picture from the file extension.
有没有办法从带有原始图像的 TBlobStream
中自动检测图像类型?
Is there any way to detect the image type automatically from a TBlobStream
with a raw image in it?
我当前的代码:
procedure LoadImageFromStream(AImage: TImage; ADataSet: TDataSet);
var
Stream: TStream;
begin
Stream := ADataSet.CreateBlobStream(Field, bmRead);
try
AImage.Picture.Graphic.LoadFromStream(Stream);
finally
Stream.Free;
end;
end
推荐答案
见这个 SO answer 用于从标题中检索文件内容.
See this SO answer for file content retrieval from header.
或者您可以使用我们的 TSynPicture
类,它将使用 Gdi+ 库处理所有类型的图片(bmp/gif/tiff/jpg/png),合二为一单班.所以你的 TPicture
可以是这个独特的类,用于任何类型的图片.与 Jpeg 或 PNG Delphi 单元相比,代码开销更少.
Or you can use our TSynPicture
class, which will handle all kind of pictures (bmp/gif/tiff/jpg/png) using Gdi+ library, in one single class. So your TPicture
can be this unique class, for any kind of picture. With less code overhead than the Jpeg or PNG Delphi units.
var Pic: TSynPicture;
Pic := TSynPicture.Create;
Pic.LoadFromStream(aStream); // will load bmp/gif/tiff/jpeg/png content
AImage.Picture.Graphic := Pic;
....
这篇关于如何将 BLOB 流中的任意图像加载到 TImage 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!