1

I am using the phonegap barcodescanner plugin from https://github.com/wildabeast/BarcodeScanner

I am encoding a text string and would like to display only the generated image. Right now I'm using the following code

window.plugins.barcodeScanner.encode(
            "TEXT_TYPE",
            strToEncode,
            function(success) {
                console.log("Encoding succeeded");
                alert("Encode success: " + success);
            },                 
            function(fail) {
                console.log("Encoding failed");
                alert("Encode failed: " + fail);
            }
        );

The success object in the alert returns a image with the encoded text below it. I would like to instead get and show only an image object from the result. Is there such a function like success.toBitmap or something like that? Or is there an alternative way I could do it?

N.B. I'm actually using this in an Oracle MAF application, so if there are some MAF specific answers it would be great too. Code is as below

<amx:verbatim id="v1">
     <![CDATA[
    <script type="text/javascript" src="js/barcodescanner.js"></script>
    <script type="text/javascript">

    function generateBarcodeFromJavaBean(strToEncode) {
        console.log("Entering generateBarcodeFromJavaBean");
        window.plugins.barcodeScanner.encode(
            "TEXT_TYPE",
            strToEncode,
            function(success) {
                console.log("Encoding succeeded");
                alert("Encode success: " + success);
            },                 
            function(fail) {
                console.log("Encoding failed");
                alert("Encode failed: " + fail);
            }
        );
    }

    </script>
]]>
</amx:verbatim>
4

1 回答 1

1

我有同样的问题并解决了这个问题:

第一:我检查了对象以知道他返回了什么

alert(JSON.stringify(success,null,4));


他返回了两个属性:格式和文件(具有图像的 src)。


第二个也是最后一个:我将图像附加到我的 div

document.getElementById("QRCode").innerHTML = '<img src="' +
success.file + '" />';



就是这样。希望它也适合你!

于 2015-10-22T10:46:14.983 回答