我正在使用此代码从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];
使用此代码初始化DevMgr
和cbWIASource
:
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上看到我可以访问ARGBData
的{{1}}成员来访问像素数据,但有一种简单的方法可以将整个图像从ImageFile
复制到FileData
吗?例如,我可以使用TBitmap
吗?
就像更新一样,我在MSDN上找到了this example。我对VB一无所知,但我想TMemoryStream
对象是Picture
的包装器。那么,可以合理地断定HBITMAP
属性是我需要的吗?