Imaging

  • Thread starter Thread starter Dave T
  • Start date Start date
D

Dave T

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>
 
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"
 
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.
 
Back
Top