WIA Scanner Image coloring
Dear All,
I use following code to scan Visiting Cards, ID Cards, ATM Card etc.
VB6 Code Code:
Dim WiaCD As New wia.CommonDialog
Set WiaDev = WiaCD.ShowSelectDevice(ScannerDeviceType, False, False)
Dim itm As wia.item
Dim ItmProp As wia.Property
varDPI = 200 ' DPI
varFac = 25.4 / varDPI ' Pixelfactor
varArea = Array(0, 0, 3.38, 2.13) ' Scan area (mm)
varMode = 4 ' 1=color 2=gray 4=b/w
varBri = -10 ' Brightness
varContr = 0 ' Contrast
' loop through each item/property and set parameters
For Each itm In WiaDev.Items
For Each ItmProp In itm.Properties
Select Case ItmProp.PropertyID
Case 4112 ' Pixel per Line (must be equal to 6151 ?)
'n = Int(varArea(2) / varFac + 0.5)
'ItmProp.Value = n
Case 6147 ' Horizontal Resolution
ItmProp.Value = varDPI
Case 6148 ' Vertical Resolution
ItmProp.Value = varDPI
Case 6149 ' Horizontal Starting Position (in pixel?)
ItmProp.Value = 0
Case 6150 ' Vertical Starting Position (in pixel?)
ItmProp.Value = 0
Case 6151 ' Horizontal Extent (Scanning Area in pixel)
n = CInt(varArea(2) * varDPI)
ItmProp.Value = n
Case 6152 ' Vertical Extent (Scanning Area in pixel)
n = CInt(varArea(3) * varDPI)
ItmProp.Value = n
Case 6154 ' Brightness
ItmProp.Value = varBri
Case 6155 ' Contrast
ItmProp.Value = varContr
Case 6146 ' Current Intent
ItmProp.Value = varMode
Case 3096
' ItmProp.Value = 0
End Select
Next
Next
' scanning
Dim item As wia.item
Set item = WiaDev.Items(1) 'the needed ITEM object = 1st scanner
Dim img As wia.ImageFile
Set img = item.Transfer 'transfers the image
'...
img.SaveFile (filename)
But I get images in black and white only. How can I get it in color.
Pls help me
Regards,
Nasreen
Re: WIA Scanner Image coloring
Code:
varMode = 4 ' 1=color 2=gray 4=b/w
Um.. did you try 1?
Re: WIA Scanner Image coloring
It is fine, I didn't notice it. Now the coloring is working fine. But I can't control the color. It is too dark and not a fine level. I changed values of Brightness and Contrast but no change.
Any idea about this ?
Nasreen
Re: WIA Scanner Image coloring
Have you tried to simply set the brightness/contrast variables to zero? You may want to visit MSDN and read up on the WIA properties and effects of those settings
Re: WIA Scanner Image coloring
It is quite bizarre to loop through like that. Many of the commonly used properties can be accessed by Name, making this unnecessary.
I've never found any comprehensive list, and it probably varies by device. But you could loop through once to create a reference document listing each property's Name, PropertyId, (Variant) SubType, and default, min, max values, whether read-only or a vector, etc. since these are all properties of a "Property" object.
Crude example from MSDN:
Code:
Dim dev 'As Device
Dim p 'As Property
Dim s 'As String
Set dev = CommonDialog1.ShowSelectDevice
For Each p In dev.Properties
s = p.Name & "(" & p.PropertyID & ")"
MsgBox s
Next
Re: WIA Scanner Image coloring
The surprising thing is, I get result all clear when I run application from the code, but if I run the application after compiling to EXE the image comes in black & while only.
What may be the issue ?
Re: WIA Scanner Image coloring
Even after set Brightness and Contrast to Zero the complied exe shows only black & white image and if we run from code it shows color image.
How this happen, what may be the wrong in the compiled EXE. ?
1 Attachment(s)
Re: WIA Scanner Image coloring
Hi All,
Here I attach the sample code of scanning I use in my project.
The code work perfectly and show color image, but after it is complied to EXE the image will be black & white only.
And another mysterious is after scan completeed a word (False) is written in the top left corner of the Form
Can anybody check the code and compile it to EXE and advise me where is the mistake is happened
With Regards,
Nasreen
Re: WIA Scanner Image coloring
Line 79 of Form1 is Printing a Boolean expression, so that explains your False. Why would something so basic be a mystery?
Get rid of your On Error GoTo Last, this may well be obscuring some exception. Or not. But in any case this is a very bad practice.
I don't see any reason why the compiled program should act any differently. Did you recompile it after changing the WiaImageIntent property value to 1 (ColorIntent)?
No scanner handy here so I can't test this.
Re: WIA Scanner Image coloring
Dear dilettante
The False print line is noticed and rectified.
I removed On Error GoTo Last and there is no any error in running the project. I compiled to EXE after changing the WiaImageIntent property value of ColorIntent to 1 but the result is same the output image is still black & white
What may be the wrong in the code ?
Nasreen
1 Attachment(s)
Re: WIA Scanner Image coloring
I'm not sure.
I dug into the boneyard here and found two old scanners. One only has TWAIN drivers but the other has WIA drivers, so I connected it.
Scanning for color I get false-color tints that seem to vary. Sometimes all blue, sometimes all yellow, all pink, or all green. So I think that's just this old scanner.
However I get color just fine (except for the weirdness) with your program both in the IDE and compiled.
I also tried a program written from scratch without all of the copy/paste bugs you have there, and it works fine compiled or in the IDE, greyscale or color (again, except for my weird tinting issues but those occur using IrfanView or Windows Photo Gallery to scan too).
To use it you will need to change the resolution in the program. My scanner doesn't do 200 DPI though it has 75, 150, 300, 600, and 1200 - so I had chosen 150 to test with.
[RESOLVED] WIA Scanner Image coloring
Dear dilettante
Thanks for your guidance and code.
I surprised again when the complied EXE of your code also doesn't give me a good result and the image was still black & white. But I could find out the issue. Really the problem is not in code or not complied exe, but it is from the Scanner itself. In my office we use scanners of 3 companies:
- WorldCard Scanner (Designed for Card Scanning), the following link provides more information
http://worldcard.penpowerinc.com/product.asp?sn=243 - HP Scanner
- Canon Scanner (http://shop.usa.canon.com/webapp/wcs...0051_253906_-1)
The first two scanners give the good result and color image in both IDE and EXE, but the 3rd one Canon Scanner which I use for my job gives color image from IDE but black & white image from complied EXE. So the exact problem is from Canon Scanner as I think.
Nasreen
Re: WIA Scanner Image coloring
Well both in your code and in the example as I posted it, the default scanner is being assumed and used.
If you take my example and set the ShowDialogs compile-time constant to True then recompile and test it both ways you can specify exactly which scanner to use, and probably even check its properties.
Maybe you are running the compiled program in a slightly different user context than the IDE, and some properties may be configured dfferently in these two contexts. This is most likely in the post-XP world.
I retested with yet another scanner that doesn't have any flaws (unlike my boneyard samples) and I see zero difference between running within the IDE and running the compiled program with this one too.