468,491 Members | 2,072 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,491 developers. It's quick & easy.

Anybody know anything about WIA (Windows Image Acqusition?)

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(Addres sOf 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.CreateWrapp erOfType(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.ReleaseCom Object(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
Nov 20 '05 #1
4 7699
Simon,

* "Simon Verona" <ne**@aphroditeuk.com> scripsit:
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/default.asp?url=/library/en-us/wia/wia/overviews/usingthewiascriptingmodel.asp>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
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
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uz**************@TK2MSFTNGP10.phx.gbl...
Simon,

* "Simon Verona" <ne**@aphroditeuk.com> scripsit:
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/de...-us/wia/wia/ov
erviews/usingthewiascriptingmodel.asp>
--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #3
Hi,

http://www.codeproject.com/dotnet/wi...asp?target=wia

Ken
------------------
"Simon Verona" <ne**@aphroditeuk.com> wrote in message
news:er**************@TK2MSFTNGP09.phx.gbl...
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(Addres sOf 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.CreateWrapp erOfType(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.ReleaseCom Object(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

Nov 20 '05 #4
On Mon, 2 Feb 2004 14:40:56 -0000, "Simon Verona"
<ne**@aphroditeuk.com> wrote:
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
Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Terry Olsen | last post: by
42 posts views Thread by (PeteCresswell) | last post: by
5 posts views Thread by =?Utf-8?B?Sm9obiBLb3R1Ynk=?= | last post: by
reply views Thread by NPC403 | last post: by
3 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.