【问题标题】:Save an IPicture to Stream, putting it on a TImage将 IPicture 保存到 Stream,将其放在 TImage 上
【发布时间】:2023-02-26 05:32:53
【问题描述】:

有人知道如何获取图片并将其存储在流中?

我的目标是在内存中使用它,并在 TImage 中向用户显示。

使用Ole保存图片文件图像可以保存为任何格式(PNG、BMP、JPG 等),但是保存在磁盘上。有人知道如何获取 IPicture 并将其保存到流中并将其放在 TImage 上吗?

我试过这种方式

// Obtaining the IPicture
  var LPicture := DPBiometria.DPSC.ConvertToPicture(pSample) as IPicture;

// This line saves the image correctly, but i dont want this way.
//  OleSavePictureFile(IPictureDisp(LPicture), 'D:\teste.jpg');

// Trying stores it on the stream and put on a bitmap or show on a TImage
  var LStream := TBytesStream.Create;
  var LOleG := TOleGraphic.Create;
  LOleG.Picture := LPicture;
  LOleG.SaveToStream(LStream);

  // When loading it on a TImage, it doesnt shows...
  // When loadgin on a TBitMap or TJPegImage, and trying to
  // save to a file, its saved with 0 bytes.

  // The TImage doesnt shows the image
  SomeTImage.LoadFromFile(LStream);

  // Saved with 0 bytes
  var Lbmp := TBitmap.Create;
  Lbmp.LoadFromStream(LStream);
  Lbmp.SaveToFile('D:\testeStream.bmp');

谢谢你的帮助

【问题讨论】:

  • 您很可能也需要 IStream,而不是 TStream。您的DPBiometria 是如何声明的,以便人们实际上能够重新编译您的代码示例?

标签: delphi com delphi-10.4-sydney


【解决方案1】:

在将图像保存到流之后和加载流之前,您没有将 TBytesStream.Position 属性设置回 0。

也就是说,如果您只想在TImage 中显示IPcture,则无需将IPicture 保存到流中,然后将流加载到TBitmap 中。由于TOleGraphic 派生自TGraphic,您可以简单地将TOleGraphic 直接分配给TImage.Picture.Graphic 属性,例如:

var LPicture := DPBiometria.DPSC.ConvertToPicture(pSample) as IPicture;

var LOleG := TOleGraphic.Create;
try
  LOleG.Picture := LPicture;
  SomeTImage.Picture.Graphic := LOleG;
finally
  LOleG.Free;
end;

【讨论】:

    猜你喜欢
    • 2013-09-26
    • 1970-01-01
    • 2013-08-27
    • 1970-01-01
    • 2013-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-11
    相关资源
    最近更新 更多