Imaging

Discussion in 'ASP .Net Web Services' started by Dave T, Dec 22, 2008.

  1. Dave T

    Dave T Guest

    In .net web app, Using Windows Image Acquisition (WIA), I'm trying to invoke
    a scanner and put the resulting image in a database. I'm trying to pass the
    image in as a string argument to a webservice that does that since VBS
    (client-side) doesn't really let you work with byte arrays. Once it gets to
    the web service I transform the string into a byte array. It all sounds good
    on paper but I get junk as an image in the database (the field is *image*
    type). Any ideas?

    <code>

    <script type = "text/vbscript" language="vbscript">

    Const ScannerDeviceType = 1
    Const GrayscaleIntent = 2
    Const UnspecifiedIntent = 0
    Const MinimizeSize = 65536
    Const wiaFormatJPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}"

    Sub DoVBScan()
    Dim ScanningDialog
    set ScanningDialog=createobject("wia.commondialog")
    Dim Img 'As ImageFile

    'Get Image
    Set Img =
    ScanningDialog.ShowAcquireImage(ScannerDeviceType,GrayscaleIntent,MinimizeSize,wiaFormatJPEG,false,true, false)

    'Convert To Jpeg as required
    If Img.FormatID <> wiaFormatJPEG Then
    Dim IP 'As New ImageProcess
    Set IP = CreateObject( "Wia.ImageProcess" )
    IP.Filters.Add IP.FilterInfos("Convert").FilterID
    IP.Filters(1).Properties("FormatID").Value = wiaFormatJPEG
    Set Img = IP.Apply(Img)
    End If

    'Create vector
    dim v 'as vector
    set v = createobject("wia.vector")
    set v = img.filedata

    'Convert image to string
    dim strImage 'as string
    strImage = v.String

    set xmlhttp = createobject("msxml2.XMLHTTP")

    'POST to web service as string parameter
    xmlhttp.open "POST",
    "http://localhost/SafeAtHome.DataAccess/Correspondence.asmx/InsertMail",false
    xmlhttp.setRequestHeader "Content-Type",
    "application/x-www-form-urlencoded"
    xmlhttp.send "EntityID=537&Image=" & strImage

    end sub

    </script>

    </code>
     
    Dave T, Dec 22, 2008
    #1
    1. Advertising

  2. On Dec 22, 8:46 pm, Dave T <> wrote:
    > In .net web app, Using Windows Image Acquisition (WIA), I'm trying to invoke
    > a scanner and put the resulting image in a database.  I'm trying to pass the
    > image in as a string argument to a webservice that does that since VBS
    > (client-side)  doesn't really let you work with byte arrays.  Once itgets to
    > the web service I transform the string into a byte array.  It all sounds good
    > on paper but I get junk as an image in the database (the field is *image*
    > type).  Any ideas?
    >
    > <code>
    >
    > <script type = "text/vbscript"  language="vbscript">
    >
    >  Const ScannerDeviceType = 1
    >  Const GrayscaleIntent = 2
    >  Const UnspecifiedIntent = 0
    >  Const MinimizeSize = 65536
    >  Const wiaFormatJPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}"
    >
    >  Sub DoVBScan()
    >     Dim ScanningDialog
    >     set ScanningDialog=createobject("wia.commondialog")
    >     Dim Img 'As ImageFile
    >
    >     'Get Image
    >     Set Img =
    > ScanningDialog.ShowAcquireImage(ScannerDeviceType,GrayscaleIntent,MinimizeS ize,wiaFormatJPEG,false,true, false)
    >
    >     'Convert To Jpeg as required
    >     If Img.FormatID <> wiaFormatJPEG Then
    >        Dim IP 'As New ImageProcess
    >        Set IP = CreateObject( "Wia.ImageProcess" )
    >        IP.Filters.Add IP.FilterInfos("Convert").FilterID
    >        IP.Filters(1).Properties("FormatID").Value = wiaFormatJPEG
    >        Set Img = IP.Apply(Img)
    >     End If
    >
    >    'Create vector
    >    dim v 'as vector
    >    set v = createobject("wia.vector")
    >    set v = img.filedata
    >
    >    'Convert image to string
    >    dim strImage 'as string
    >    strImage = v.String
    >
    >    set xmlhttp = createobject("msxml2.XMLHTTP")
    >
    >    'POST to web service as string parameter
    >    xmlhttp.open "POST",
    > "http://localhost/SafeAtHome.DataAccess/Correspondence.asmx/InsertMail",false
    >    xmlhttp.setRequestHeader "Content-Type",
    > "application/x-www-form-urlencoded"
    >    xmlhttp.send "EntityID=537&Image=" & strImage
    >
    >  end sub
    >
    > </script>
    >
    > </code>


    The content type "application/x-www-form-urlencoded" is inefficient
    for sending large quantities of binary data or text containing non-
    ASCII characters. The content type "multipart/form-data" should be
    used for submitting forms that contain files, non-ASCII data, and
    binary data. I think you have to use "application/x-www-form-
    urlencoded"
     
    Alexey Smirnov, Dec 22, 2008
    #2
    1. Advertising

  3. Dave T

    Dave T Guest

    Thanks Alexey ... That didn't help but I have something to investigate now.
    I'm not even so sure I'm using that WIA vector properly. It seems like a
    lot of data is being truncated.

    "Alexey Smirnov" wrote:

    > On Dec 22, 8:46 pm, Dave T <> wrote:
    > > In .net web app, Using Windows Image Acquisition (WIA), I'm trying to invoke
    > > a scanner and put the resulting image in a database. I'm trying to pass the
    > > image in as a string argument to a webservice that does that since VBS
    > > (client-side) doesn't really let you work with byte arrays. Once it gets to
    > > the web service I transform the string into a byte array. It all sounds good
    > > on paper but I get junk as an image in the database (the field is *image*
    > > type). Any ideas?
    > >
    > > <code>
    > >
    > > <script type = "text/vbscript" language="vbscript">
    > >
    > > Const ScannerDeviceType = 1
    > > Const GrayscaleIntent = 2
    > > Const UnspecifiedIntent = 0
    > > Const MinimizeSize = 65536
    > > Const wiaFormatJPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}"
    > >
    > > Sub DoVBScan()
    > > Dim ScanningDialog
    > > set ScanningDialog=createobject("wia.commondialog")
    > > Dim Img 'As ImageFile
    > >
    > > 'Get Image
    > > Set Img =
    > > ScanningDialog.ShowAcquireImage(ScannerDeviceType,GrayscaleIntent,MinimizeS ize,wiaFormatJPEG,false,true, false)
    > >
    > > 'Convert To Jpeg as required
    > > If Img.FormatID <> wiaFormatJPEG Then
    > > Dim IP 'As New ImageProcess
    > > Set IP = CreateObject( "Wia.ImageProcess" )
    > > IP.Filters.Add IP.FilterInfos("Convert").FilterID
    > > IP.Filters(1).Properties("FormatID").Value = wiaFormatJPEG
    > > Set Img = IP.Apply(Img)
    > > End If
    > >
    > > 'Create vector
    > > dim v 'as vector
    > > set v = createobject("wia.vector")
    > > set v = img.filedata
    > >
    > > 'Convert image to string
    > > dim strImage 'as string
    > > strImage = v.String
    > >
    > > set xmlhttp = createobject("msxml2.XMLHTTP")
    > >
    > > 'POST to web service as string parameter
    > > xmlhttp.open "POST",
    > > "http://localhost/SafeAtHome.DataAccess/Correspondence.asmx/InsertMail",false
    > > xmlhttp.setRequestHeader "Content-Type",
    > > "application/x-www-form-urlencoded"
    > > xmlhttp.send "EntityID=537&Image=" & strImage
    > >
    > > end sub
    > >
    > > </script>
    > >
    > > </code>

    >
    > The content type "application/x-www-form-urlencoded" is inefficient
    > for sending large quantities of binary data or text containing non-
    > ASCII characters. The content type "multipart/form-data" should be
    > used for submitting forms that contain files, non-ASCII data, and
    > binary data. I think you have to use "application/x-www-form-
    > urlencoded"
    >
     
    Dave T, Dec 22, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robin

    Imaging in ASP.Net

    Robin, Nov 4, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    457
    Kevin Spencer
    Nov 8, 2004
  2. SB
    Replies:
    0
    Views:
    378
  3. Bernhard Messerer

    Transparency in Java Imaging

    Bernhard Messerer, Aug 6, 2003, in forum: Java
    Replies:
    5
    Views:
    7,607
    Bernhard Messerer
    Aug 11, 2003
  4. Allen E. Scharfenberg

    Java Advanced Imaging at 204x98 dpi

    Allen E. Scharfenberg, Oct 31, 2003, in forum: Java
    Replies:
    1
    Views:
    778
  5. Millian Brave
    Replies:
    0
    Views:
    408
    Millian Brave
    Nov 3, 2003
Loading...

Share This Page