首页 > 解决方案 > 从 MemoryStream 加载 TGPBitmap

问题描述

我被要求更正旧版 Delphi 程序中的一个问题(与此问题无关)。在修复了缺少组件的一些问题后,我现在被一些 GDI Plus 功能所困扰,这使我无法编译程序。使用它的功能之一是:

function TDownLoadItem.LoadRawBitmapFromStream(var bm: TBitmap): Boolean;
var
  image: TGPBitmap;
begin
  Result := False;
  if Content.Size = 0 then
    exit;

  // NOTE: Content is a TMemoryStream, declared globally.
  image := GDIPlusHelper.LoadBitmapFromStream(Content); // <== This is where the problem is....

  try
    bm.Width := image.GetWidth;
    bm.Height := image.GetHeight;
    with TGPGraphics.Create(bm.Canvas.Handle) do
      try
        DrawImage(image, 0, 0, image.GetWidth, image.GetHeight);
        Result := True;
      finally
        Free;
      end;
  finally
    image.Free;
  end;
end;

我认为(不确定)使用的最后一个 Delphi 版本是 2006 年,我使用的是 Delphi Rio 10.3。

网上我找到了GDI+ 1.2,但这并不能解决问题。过程 LoadBitmapFromStream 不会在这些库中退出。GDIPlusHelper 显然已重命名为 GDIPlusHelpers,并且大多数代码已从类更改为接口。我怀疑使用了旧版本的 GDI Plus 库,但我找不到这些。

重新编写代码将过于复杂,因为它需要 Content 是 IStream 而不是 TMemoryStream。此外,简单地使用 TBitmap 也不可行,因为其他代码(未显示)使用特定于 TGPBitmap 的功能(例如 RotateFlip)。

有关如何解决/解决此问题的任何建议?提前致谢!

标签: delphigdi+

解决方案


推荐阅读