I don't think I can use your suggestion. I try to make it easy to see the
problem by shorting the code but I'm afriad I cut out too much code. Below
might be more then required to show the problem but I hope I didn't cut
anything relavent.
I believe the problen code starts where I left the blank lines below.
Dim wiaManager As WiaClass = Nothing ' WIA manager COM object
Dim wiaDevs As CollectionClass = Nothing ' WIA devices collection COM object
Dim wiaRoot As ItemClass = Nothing ' WIA root device COM object
Dim wiaPics As CollectionClass = Nothing ' WIA collection COM object
Dim wiaItem As ItemClass = Nothing ' WIA image COM object
Dim imageFileName As String
wiaManager = New WiaClass ' create COM instance of WIA manager
wiaDevs = wiaManager.Devices '
wiaDevs = wiaManager.Devices ' as CollectionClass; ' call Wia.Devices to get
all devices
If wiaDevs Is Nothing OrElse wiaDevs.Count = 0 Then
MessageBox.Show("No WIA devices found!", "WIA", MessageBoxButtons.OK,
MessageBoxIcon.Stop)
Application.Exit()
Return Nothing
End If
Dim selectUsingUI As Object = System.Reflection.Missing.Value ' = Nothing
wiaRoot = CType(wiaManager.Create(selectUsingUI), ItemClass) ' Display form
to let the user select device
If wiaRoot Is Nothing Then ' nothing to do
Return Nothing
End If
wiaPics = wiaRoot.GetItemsFromUI(WiaFlag.SingleImage,
WiaIntent.ImageTypeColor) 'Open acquisition form to get a single image.
If wiaPics Is Nothing Then
Return Nothing
End If
Dim wiaObj As Object = wiaPics.Item(0)
wiaItem = CType(Marshal.CreateWrapperOfType(wiaObj, GetType(ItemClass)),
ItemClass)
imageFileName = Path.GetTempFileName() ' create temporary file for image
wiaItem.Transfer(imageFileName, False) ' Now do the scan and then transfer
picture to our temporary file (only way to get it)
Dim zz As Image = Image.FromFile(imageFileName) ' create Image instance from
file
AcquireScanner = zz.Clone
zz.Dispose() 'Unlock the file
zz = Nothing
File.Delete(imageFileName)
When I get the image from the file the file remains locked so the Delete
fails with a "used by another process"
So I tried using a clone and disposing the obtained image.
But that didn't fix the problem.
Can you help?