Anybody know anything about WIA (Windows Image Acqusition?)

S

Simon Verona

I'm using wia in a vb.net project to capture images from a scanner.. This
works fine.

However, I want to control the way that images are scanned - ie B+W,
Greyscale and resolution etc, but can't work out how to. My code for
scanning is below (sorry it's a bit messy - it's been chopped and changed
around a lot)... There seems to be very little documentation on WIA, can
anybody help me with this ???

Code is :

Private Sub Getscanner()

' Setup Scanning and get scanner

txtStatus.Text = "Connecting to Scanner/Camera"

Try

wiadev = wia.ShowSelectDevice()

Catch ex As Exception

txtStatus.Text = "Could not connect to scanner/camera"

Exit Sub

End Try

Dim str As WIA.Property

For Each str In wiadev.Properties

Try

Debug.WriteLine("Property : " & str.Name & " = " & CStr(str.Value))

Catch

End Try

Next

txtStatus.Text = "Connected to Scanner/camera"

End Sub







Private Sub CaptureImages()

Dim FileName As String

Dim count As Int32

Dim tmp As Object

Dim image As Image

Dim gr As System.Drawing.Graphics

Dim prop As System.Drawing.Imaging.PropertyItem

Dim scale As Decimal

Dim tmpfilename As String

Dim Cb As System.Drawing.Image.GetThumbnailImageAbort = New
System.Drawing.Image.GetThumbnailImageAbort(AddressOf AbortImage)

Dim ImageCount As Int32

Getscanner()

txtStatus.Text = "Getting Images.."

'Try

' wiaPics = wiaRoot.Children. 'GetItemsFromUI(WIALib.WiaFlag.UseCommonUI,
WIALib.WiaIntent.ImageTypeColor)

'Catch ex As Exception

' MsgBox(ex.Message)

' Exit Sub

' End Try

Dim WiaPics As WIA.ItemClass

Dim WiaItem1 As WIA.ItemsClass

Dim wiaitem As WIA.ItemClass

Dim WiaImage As WIA.ImageFileClass



WiaItem1 = wiadev.Items

ImageCount = WiaItem1.Count

Dim offset As Int32 = 0

' Try

For count = 1 To WiaItem1.Count

wiaitem = WiaItem1.Item(count)

'wiaItem = System.Runtime.InteropServices.Marshal.CreateWrapperOfType(tmp,
GetType(WIALib.ItemClass))

Do

FileName = DirName & "\img" & Format(count + offset, "0000") & ".jpg"

If System.IO.File.Exists(FileName) Then offset = offset + 1

Loop Until System.IO.File.Exists(FileName) = False

txtStatus.Text = "Getting Image - " & count & " of " & ImageCount

Application.DoEvents()

tmpfilename = System.IO.Path.GetTempFileName

System.IO.File.Delete(tmpfilename)

Try

tmp = wiaitem.Transfer()

tmp.SaveFile(tmpfilename)

' tmp.Transfer(tmpfilename, False)

'System.Runtime.InteropServices.Marshal.ReleaseComObject(wiaItem)

image = System.Drawing.Bitmap.FromFile(tmpfilename)

Try

System.IO.File.Delete(DirName & "\tmppic" & count & ".jpg")

Catch ex As Exception

'txtstatus.Text = "Error deleting file : " & Err.Description

' Application.DoEvents()

End Try

' If image.Width > 500 Then

'scale = 500 / image.Width

'image = image.GetThumbnailImage(500, Int(image.Height * scale), Cb,
IntPtr.Zero)

'End If

PictureBox1.Image = image

image.Save(FileName)

image = Nothing

RaiseEvent ImageLoaded()

Catch ex As Exception

'MsgBox(ex.Message)

End Try

' Catch

' 'txtstatus.Text = "Failed..."

' End Try

Next

Me.Close()

End Sub



----



Many thanks in advance

Simon
 
H

Herfried K. Wagner [MVP]

Simon,

* "Simon Verona said:
I'm using wia in a vb.net project to capture images from a scanner.. This
works fine.

However, I want to control the way that images are scanned - ie B+W,
Greyscale and resolution etc, but can't work out how to. My code for
scanning is below (sorry it's a bit messy - it's been chopped and changed
around a lot)... There seems to be very little documentation on WIA, can
anybody help me with this ???

Are you sure there is little documentation?

<http://msdn.microsoft.com/library/d...a/wia/overviews/usingthewiascriptingmodel.asp>
 
S

Simon Verona

Thanks Herfried,

I've seen this documentation, but it doesn't appear to have too many useful
examples of using and setting properties which is where I think I need to be
playing... I was hoping somebody else had got a working example that would
save me working it out by trial and error..

Regards
Simon
 
T

Tim McGarvey

I'm using wia in a vb.net project to capture images from a scanner.. This
works fine.

However, I want to control the way that images are scanned - ie B+W,
Greyscale and resolution etc, but can't work out how to. My code for
scanning is below (sorry it's a bit messy - it's been chopped and changed
around a lot)... There seems to be very little documentation on WIA, can
anybody help me with this ???
[snip]

Well, I don't have any suggestions for you, Simon, but that's exactly
the same problem I'm running up against. I don't want to have to
abandon the scripting model and do lower-level wia coding if I don't
have to, but it seems like the only solution I can find. MSDN lists
it as one of the technical limitations of the scripting model, that
you cannot set properties.

Did you have any success with this, and if so, how?

Thanks,

Tim McGarvey
Back East Consulting

r e m o v e junk f r o m e m a i l t o r e p l y
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top