如何将任意图像从BLOB流加载到TImage? [英] How to load an arbitrary image from a BLOB stream into a TImage?

查看:190
本文介绍了如何将任意图像从BLOB流加载到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答案从标题文件内容检索。

See this SO answer for file content retrieval from header.

或者您可以使用我们的 TSynPicture class ,它将使用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屋!

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