G
Guest
Hi!
I want to scan a multipage-document into
a TIFF-file from C#. The scanner has WIA-support
and a feeder.
The following code works:
IDeviceManager mng=new DeviceManagerClass();
foreach(IDeviceInfo i in mng.DeviceInfos)
{
MessageBox.Show(i.Type.ToString()+" "+i.DeviceID);
IDevice dev=i.Connect();
foreach(IItem item in dev.Items)
{
MessageBox.Show(item.ItemID);
IImageFile
file=(IImageFile)item.Transfer("{00000000-0000-0000-0000-000000000000}"/*WIA
..FormatID. .wiaFormatTIFF*/);
file.SaveFile("C:\\file.tif");
}
}
But I had to use foreach and will scan from every scanner
around which makes no sense.
The code should have been:
IDeviceManager mng=new DeviceManagerClass();
IDevice dev=mng.DeviceInfos[0].Connect();
IItem item=dev.Items[0];
IImageFile
file=(IImageFile)item.Transfer("{00000000-0000-0000-0000-000000000000}"
/*WIA.FormatID. .wiaFormatTIFF*/);
file.SaveFile("C:\\file.tif");
However this won't compile:
d:\usr\prj\wiabrothertest\wiabrothertest\form1.cs(91,4): error CS1546: Die
Eigenschaft oder der Indexer "this" wird von der Sprache nicht unterstützt
wird. Versuchen Sie direkt die Accessor-Methode
"WIA.IDeviceInfos.get_Item(ref object)" aufzurufen.
d:\usr\prj\WIABrotherTest\WIABrotherTest\bin\Debug\Interop.WIA.dll:
(Verknüpfte Datei)
If I change it into:
IDeviceManager mng=new DeviceManagerClass();
IDevice dev=mng.DeviceInfos.get_Item(0).Connect();
IItem item=dev.Items[0];
IImageFile
file=(IImageFile)item.Transfer("{00000000-0000-0000-0000-000000000000}"
/*WIA.FormatID. .wiaFormatTIFF*/);
file.SaveFile("C:\\file.tif");
I will get this compiler error:
d:\usr\prj\wiabrothertest\wiabrothertest\form1.cs(121,16): error CS1502: Die
beste Übereinstimmung für die überladene Methode
'WIA.IDeviceInfos.get_Item(ref object)' hat einige ungültige Argumente
d:\usr\prj\wiabrothertest\wiabrothertest\form1.cs(121,41): error CS1503:
Argument '1': kann nicht von 'int' zu 'ref object' konvertiert werden
It says it can't convert int into ref object
How comes this?
How can I use the WIA-automation library easily from .NET/C#?
BTW:
I went to MS-Downloadcenter, searched for "WIA automation" and downloaded
the sdk.
I used regsvr32 to register the dll and then added a reference to "Wia
automation V2"
in my C#-project. Then the above code can be compiled and works under my XP
SP1^
Many thanks in advance
I want to scan a multipage-document into
a TIFF-file from C#. The scanner has WIA-support
and a feeder.
The following code works:
IDeviceManager mng=new DeviceManagerClass();
foreach(IDeviceInfo i in mng.DeviceInfos)
{
MessageBox.Show(i.Type.ToString()+" "+i.DeviceID);
IDevice dev=i.Connect();
foreach(IItem item in dev.Items)
{
MessageBox.Show(item.ItemID);
IImageFile
file=(IImageFile)item.Transfer("{00000000-0000-0000-0000-000000000000}"/*WIA
..FormatID. .wiaFormatTIFF*/);
file.SaveFile("C:\\file.tif");
}
}
But I had to use foreach and will scan from every scanner
around which makes no sense.
The code should have been:
IDeviceManager mng=new DeviceManagerClass();
IDevice dev=mng.DeviceInfos[0].Connect();
IItem item=dev.Items[0];
IImageFile
file=(IImageFile)item.Transfer("{00000000-0000-0000-0000-000000000000}"
/*WIA.FormatID. .wiaFormatTIFF*/);
file.SaveFile("C:\\file.tif");
However this won't compile:
d:\usr\prj\wiabrothertest\wiabrothertest\form1.cs(91,4): error CS1546: Die
Eigenschaft oder der Indexer "this" wird von der Sprache nicht unterstützt
wird. Versuchen Sie direkt die Accessor-Methode
"WIA.IDeviceInfos.get_Item(ref object)" aufzurufen.
d:\usr\prj\WIABrotherTest\WIABrotherTest\bin\Debug\Interop.WIA.dll:
(Verknüpfte Datei)
If I change it into:
IDeviceManager mng=new DeviceManagerClass();
IDevice dev=mng.DeviceInfos.get_Item(0).Connect();
IItem item=dev.Items[0];
IImageFile
file=(IImageFile)item.Transfer("{00000000-0000-0000-0000-000000000000}"
/*WIA.FormatID. .wiaFormatTIFF*/);
file.SaveFile("C:\\file.tif");
I will get this compiler error:
d:\usr\prj\wiabrothertest\wiabrothertest\form1.cs(121,16): error CS1502: Die
beste Übereinstimmung für die überladene Methode
'WIA.IDeviceInfos.get_Item(ref object)' hat einige ungültige Argumente
d:\usr\prj\wiabrothertest\wiabrothertest\form1.cs(121,41): error CS1503:
Argument '1': kann nicht von 'int' zu 'ref object' konvertiert werden
It says it can't convert int into ref object
How comes this?
How can I use the WIA-automation library easily from .NET/C#?
BTW:
I went to MS-Downloadcenter, searched for "WIA automation" and downloaded
the sdk.
I used regsvr32 to register the dll and then added a reference to "Wia
automation V2"
in my C#-project. Then the above code can be compiled and works under my XP
SP1^
Many thanks in advance