convert image or imageobject to binary in qml

728
2
Jump to solution
12-16-2020 12:51 AM
rsharma
Occasional Contributor III

Hi,

I want to convert image object url image to binary, but unable to do so, as further i have to conver it to base64.

I am not getting help from anywhere, i tried alot, thanks in advance.

i m trying like this

                var buffer_data = imageObject.toArrayBuffer();

but when i convert it into base64 it do not convert properly

with the fnc below. but if any string i want to convert, it converts properly

function arrayBufferToBase64( buffer ) {
    var binary = '';
    var bytes = new Uint8Array( buffer );
    var len = bytes.byteLength;
    for (var i = 0; i < len; i++) {
        binary += String.fromCharCode( bytes[ i ] );
    }
    return Qt.btoa( binary );
}

 Please help. i am stuck in it from last 3weeks

0 Kudos
1 Solution

Accepted Solutions
rsharma
Occasional Contributor III

HI 

please have the solution of my problem

 var s =imageObject.toArrayBuffer('jpeg') ;
 var b = AppFramework.binaryData(s); //  produces a binary data object
 console.log(b.base64);
 imageObject.loadFromData(b.base64);

View solution in original post

0 Kudos
2 Replies
JamesBallard1
Esri Contributor

Hi @rsharma ,

 

   Is there any ArcGIS Runtime workflow you're trying to achieve with this? If not it's a bit off topic and more related to QML general programming. 

Generally speaking, whenever we've had to do image processing we use the QQuickImageProvider pattern, which does require a bit of C++ logic. I don't know if this directly applies to your use case, but I hope it is helpful.

https://github.com/Esri/arcgis-runtime-samples-qt/blob/master/ArcGISRuntimeSDKQt_CppSamples/Maps/Tak...

https://doc.qt.io/qt-5/qtquick-imageprovider-example.html

https://doc.qt.io/qt-5/qquickimageprovider.html 

0 Kudos
rsharma
Occasional Contributor III

HI 

please have the solution of my problem

 var s =imageObject.toArrayBuffer('jpeg') ;
 var b = AppFramework.binaryData(s); //  produces a binary data object
 console.log(b.base64);
 imageObject.loadFromData(b.base64);
0 Kudos