delphi - 如何在不将扫描图像保存到磁盘的情况下将扫描图像从 WIA ImageFile 传输到 TBitmap?

标签 delphi delphi-xe2 wia

我正在使用此代码从 WIA 获取扫描图像:

const
  wiaFormatJPEG = '{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}';
  wiaFormatPNG = '{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}';
var
  CommonDialog: ICommonDialog;
  AImage: IImageFile;
  i: Integer;
begin
  CommonDialog := CreateOleObject('WIA.CommonDialog') as ICommonDialog;

  for i := 1 to Scanner.Properties.Count do
  begin
    if (Scanner.Properties[i].Name = 'Horizontal Resolution') or
      (Scanner.Properties[i].Name = 'Vertical Resolution') then
      Scanner.Properties[i].Set_Value(72)
    else if Scanner.Properties[i].Name = 'Horizontal Extent' then
      Scanner.Properties[i].Set_Value(Round(8.27 * 72))
    else if Scanner.Properties[i].Name = 'Vertical Extent' then
      Scanner.Properties[i].Set_Value(Round(11.00 * 72));
  end;
  AImage := IUnknown(CommonDialog.ShowTransfer(Scanner, wiaFormatPNG, True)) as IImageFile;
  //Save the image
  AImage.SaveFile('D:\1.' + AImage.FileExtension);
  imgImage.Picture.LoadFromFile('D:\1.' + AImage.FileExtension);
  DeleteFile('D:\1.' + AImage.FileExtension);
end;

Scanner 使用以下代码初始化:

Scanner := DevMgr.DeviceInfos[Integer(cbWIASource.Items.Objects[cbWIASource.ItemIndex])].Connect.Items[1];

并且 DevMgrcbWIASource 使用此代码进行初始化:

DevMgr := CreateOleObject('WIA.DeviceManager') as IDeviceManager;
for i := 1 to DevMgr.DeviceInfos.Count do
    for j := 1 to DevMgr.DeviceInfos[i].Properties.Count do
      if DevMgr.DeviceInfos[i].Properties[j].Name = 'Name' then
      begin
        cbWIASource.Items.AddObject(DevMgr.DeviceInfos[i].Properties[j].Get_Value, TObject(i));
        Break;
      end;

我想知道是否有一种方法可以在不先将扫描文档保存到磁盘的情况下复制它。我在 MSDN 上读到我可以访问 ImageFileARGBData 成员来访问像素数据,但是有没有一种简单的方法可以从 FileData 复制整个图像> 到 TBitmap?例如,我可以使用 TMemoryStream 吗?


作为更新,我找到了this example在 MSDN 上。我对 VB 一无所知,但我猜 Picture 对象是 HBITMAP 的包装器。那么,得出 ImageFile.Picture 属性是我需要的结论是否合乎逻辑?

最佳答案

IImageFile 有一个属性 FileData,通过 IVector.BinaryData 提供对二进制图像数据的访问。

关于delphi - 如何在不将扫描图像保存到磁盘的情况下将扫描图像从 WIA ImageFile 传输到 TBitmap?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13108742/

相关文章:

delphi - 将应用程序(exe 文件)嵌入到另一个 exe 文件中(类似 mozEmbed)

delphi - DrawText with DT_CALCRECT - 有没有办法计算矩形的高度而不修改宽度(使用大字符串)?

delphi - 如何获取通用 TList<Integer> 中的最大值?

delphi - 您可以重写类构造函数并使用继承吗?

c# - WIA: device.ExecuteCommand(CommandID.wiaCommandTakePicture);返回空

camera - 在WIA中,如何将我的程序添加到从数码相机获取图像的程序列表中?

delphi - 编辑路径中的第一个INI文件

delphi - 嵌入式 Firebird/Delphi 会导致防火墙 'hit' 吗?

delphi - 解码base64会增加额外的空格

c++ - 使用 WIA 或 TWAIN 扫描页面