3
我使用这个代码,以获得从WIA扫描图像:如何将扫描图像从WIA ImageFile传输到TBitmap而不将其保存到磁盘?
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上读到我可以访问ImageFile
的ARGBData
成员来访问像素数据,但是有没有简单的方法将整个图像从FileData
复制到TBitmap
?例如,我可以使用TMemoryStream
?
只是作为一个更新,我在MSDN上找到this example。我对VB一无所知,但我猜Picture
对象是围绕HBITMAP
的包装。那么,合乎逻辑的结论是ImageFile.Picture
属性是我需要的吗?
什么'IImageFile'真的叫什么名字? Websearch并没有听说过它。 –
@David,这一个http://msdn.microsoft.com/en-us/library/windows/desktop/ms630506(v=vs.85).aspx – TLama
好吧,所以它的真名是'ImageFile'。 –