Results 1 to 13 of 13

Thread: WIA Scanner Image coloring

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    WIA Scanner Image coloring

    Dear All,

    I use following code to scan Visiting Cards, ID Cards, ATM Card etc.

    VB6 Code Code:
    1. Dim WiaCD As New wia.CommonDialog
    2. Set WiaDev = WiaCD.ShowSelectDevice(ScannerDeviceType, False, False)
    3. Dim itm As wia.item
    4. Dim ItmProp As wia.Property
    5. varDPI = 200                    ' DPI
    6. varFac = 25.4 / varDPI          ' Pixelfactor
    7. varArea = Array(0, 0, 3.38, 2.13) ' Scan area (mm)
    8. varMode = 4                     ' 1=color 2=gray 4=b/w
    9. varBri = -10                    ' Brightness
    10. varContr = 0                    ' Contrast
    11. ' loop through each item/property and set parameters
    12. For Each itm In WiaDev.Items
    13.  For Each ItmProp In itm.Properties
    14.   Select Case ItmProp.PropertyID
    15.   Case 4112 ' Pixel per Line (must be equal to 6151 ?)
    16.    'n = Int(varArea(2) / varFac + 0.5)
    17.    'ItmProp.Value = n
    18.   Case 6147 ' Horizontal Resolution
    19.    ItmProp.Value = varDPI
    20.   Case 6148 ' Vertical Resolution
    21.    ItmProp.Value = varDPI
    22.   Case 6149 ' Horizontal Starting Position (in pixel?)
    23.    ItmProp.Value = 0
    24.   Case 6150 ' Vertical Starting Position (in pixel?)
    25.    ItmProp.Value = 0
    26.   Case 6151 ' Horizontal Extent (Scanning Area in pixel)
    27.    n = CInt(varArea(2)  * varDPI)
    28.    ItmProp.Value = n
    29.   Case 6152 ' Vertical Extent (Scanning Area in pixel)
    30.    n = CInt(varArea(3) * varDPI)
    31.    ItmProp.Value = n
    32.   Case 6154 ' Brightness
    33.    ItmProp.Value = varBri
    34.   Case 6155 ' Contrast
    35.    ItmProp.Value = varContr
    36.   Case 6146 ' Current Intent
    37.    ItmProp.Value = varMode
    38.   Case 3096
    39.   ' ItmProp.Value = 0
    40.   End Select
    41.  Next
    42. Next
    43. ' scanning
    44. Dim item As wia.item
    45. Set item = WiaDev.Items(1) 'the needed ITEM object = 1st scanner
    46. Dim img As wia.ImageFile
    47. Set img = item.Transfer 'transfers the image
    48. '...
    49. img.SaveFile (filename)

    But I get images in black and white only. How can I get it in color.

    Pls help me

    Regards,
    Nasreen
    Last edited by nasreen; Feb 12th, 2012 at 12:52 PM. Reason: Attachment removed

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: WIA Scanner Image coloring

    Code:
    varMode = 4                     ' 1=color 2=gray 4=b/w
    Um.. did you try 1?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    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

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    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

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    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 ?

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    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. ?

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    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
    Attached Files Attached Files

  9. #9
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    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.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    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

  11. #11
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    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.
    Attached Files Attached Files
    Last edited by dilettante; Feb 16th, 2012 at 08:07 PM. Reason: updated attachment a little

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Apr 2005
    Posts
    105

    Resolved [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:

    1. WorldCard Scanner (Designed for Card Scanning), the following link provides more information
      http://worldcard.penpowerinc.com/product.asp?sn=243
    2. HP Scanner
    3. 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

  13. #13
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    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.
    Last edited by dilettante; Feb 15th, 2012 at 09:07 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width