delphi - 从 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)。
有关如何解决/解决此问题的任何建议?提前致谢!
解决方案
推荐阅读
- file - 如何从基于 SwiftUI 文档的应用程序中将多个文件保存在包文件夹中?
- javascript - JavaScript:如何在 innerHTML 的每个行项目周围呈现边框
- javascript - 如何防止在快速拖动元素上的 dragend 后触发 dragstart?
- linux - 当文件名有空格时,Bash if 语句失败
- mysql - 如何手动将分区详细信息添加到配置单元元存储表中?
- python - 如何在 Python 中为类添加额外的属性?
- arduino - 使用 Arduino 读取 BLE
- reactjs - reactjs 与核心 3.1 api 控制器。获取 json 错误而不是返回数据
- azure - 如何使用 B2C 自定义用户流使用电子邮件填充显示名称
- azure - 如何使用 2 因素身份验证通过 Powershell 登录 Azure?