简体   繁体   English

如何将扫描图像从WIA ImageFile传输到TBitmap而不将其保存到磁盘?

[英]How to transfer a scanned image from WIA ImageFile to TBitmap without saving it to disk?

I'm using this code to acquire the scanned image from 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 is initialized using this code: 使用以下代码初始化Scanner程序:

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

And DevMgr and cbWIASource are initialized using this code: 并使用以下代码初始化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;

I was wondering if there is a way to copy the scanned document without first saving it to the disk. 我想知道是否有办法复制扫描的文档而不先将其保存到磁盘。 I read on MSDN that I can access ARGBData member of ImageFile to access pixel data, but is there a simple way to copy the entire image from FileData to TBitmap ? 我在MSDN上读到我可以访问ImageFile ARGBData成员来访问像素数据,但是有一种简单的方法可以将整个图像从FileData复制到TBitmap吗? For instance, can I use a TMemoryStream ? 例如,我可以使用TMemoryStream吗?


Just as an update, I found this example on MSDN. 就像更新一样,我在MSDN上找到了这个例子 I know nothing about VB, but I guess the Picture object is a wrapper around HBITMAP . 我对VB一无所知,但我想Picture对象是HBITMAP的包装器。 So, is it logical to conclude that the ImageFile.Picture property is what I need? 那么,结论是ImageFile.Picture属性是我需要的是合乎逻辑的吗?

IImageFile具有FileData属性,可通过IVector.BinaryData访问二进制图像数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM