2012-10-28 33 views
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]; 

而且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


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

+0

什么'IImageFile'真的叫什么名字? Websearch并没有听说过它。 –

+1

@David,这一个http://msdn.microsoft.com/en-us/library/windows/desktop/ms630506(v=vs.85).aspx – TLama

+0

好吧,所以它的真名是'ImageFile'。 –

回答

1

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

相关问题