Atalasoft
Welcome to Atalasoft Community Sign in | Join | Help
in

ImgXTwain scanning with Javascript, need byte array

Last post 21 Aug 2007, 5:32 PM by JBrechtel. 4 replies.
Sort Posts: Previous Next
  •  16 Aug 2007, 3:18 PM 12504

    ImgXTwain scanning with Javascript, need byte array

    Attachment: script.txt

    Hi, I'm trying to scan an image with ImgXTwain in javascript, get the byte array and encode it to base64 for posting. I don't seem to be able to figure out how to get the image into a byte array...

    Attached is what I have, I get a 'Type Mismatch' error on the second to last line of the attached script (imgx.Export...)

    What am I doing wrong?

  •  16 Aug 2007, 3:45 PM 12505 in reply to 12504

    Re: ImgXTwain scanning with Javascript, need byte array

    Try using ToMemoryFileVariant instead.
    Glenn Chittenden Jr.
    Atalasoft Development Team
  •  20 Aug 2007, 2:27 PM 12511 in reply to 12505

    Re: ImgXTwain scanning with Javascript, need byte array

    Thanks for the reply,

    I'm trying that now, am still having problems (imgBytes[0] is null, imgBytes.length is null, though alert(imgBytes) shows binary data).

     
    Javascript isn't my native tongue so to speak, so the problem is probably on my end at this point.

     

     Are there any examples using ToMemoryFileVariant in javascript?

     

    Thanks 

  •  21 Aug 2007, 5:04 PM 12513 in reply to 12511

    Re: ImgXTwain scanning with Javascript, need byte array

    For what it's worth, I have gotten past the initial problem of the array being unusable by following the steps outlined in the knowledge base regarding this.

    However, the object used to get at the array is ADODB.Stream which is disabled in IE by default (in Vista at least).

    I'm still looking into other ways of accessing the byte array returned from ToMemoryFileVariant...any tips would be greatly appreciated.   

  •  21 Aug 2007, 5:32 PM 12514 in reply to 12513

    Re: ImgXTwain scanning with Javascript, need byte array

    This code seems to do what I need, incase anyone else runs into the same problem I did.

     

     

     

     //convert the image to base64 JPG and prepare for uploading
     var imgx = document.getElementById('scantest_ImgX');
     imgx.Images.Replace(imgx.Support.GetImageFromVariant(Image));
     var imgBytes = imgx.Export.ToMemoryFileVariant(1);
     var xmlDoc = new ActiveXObject("MSXML2.DOMDocument");
     xmlSOAP.loadXML('<?xml version="1.0" encoding="utf-8"?>'+
     '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '+
     'xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> '+
      '<soap:Body>'+
       '<UploadData xmlns="http://tempuri.org/" >'+
        '<imageData></imageData>'+
       '</UploadData>'+
      '</soap:Body>'+
     '</soap:Envelope>');
     
     // create a new node and set binary content
     var imgNode = xmlSOAP.selectSingleNode("//imageData");
     imgNode.dataType = "bin.base64";
     // store file content into XML node
     imgNode.nodeTypedValue = imgBytes;

     alert(xmlDoc.xml);
     

View as RSS news feed in XML