From 75180f2a016ddc9eb0948a932a0d042a69cddd62 Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Thu, 7 Sep 2017 20:30:08 +0200 Subject: [PATCH] Encode base64 via c++ code --- retroshare-qml-app/src/androidimagepicker.h | 60 ++++++++++++++++ retroshare-qml-app/src/components/Faces.qml | 79 +++++++++++---------- 2 files changed, 101 insertions(+), 38 deletions(-) diff --git a/retroshare-qml-app/src/androidimagepicker.h b/retroshare-qml-app/src/androidimagepicker.h index ad5f0e302..4187489de 100644 --- a/retroshare-qml-app/src/androidimagepicker.h +++ b/retroshare-qml-app/src/androidimagepicker.h @@ -9,6 +9,8 @@ #include #include +#include "qpainter.h" + #ifdef __ANDROID__ # include @@ -60,7 +62,65 @@ public slots: qDebug() << "imageToBase64() encoded" ; + return encoded; + } + + static QString faceImage (QVariantList onloads, int size) + { + QImage result(size, size, QImage::Format_ARGB32_Premultiplied); + QPainter painter(&result); + + + int counter = 0; + for (QVariantList::iterator j = onloads.begin(); j != onloads.end(); j++) + { + QString path = (*j).toString(); + QImageReader reader; + reader.setFileName(path); + QImage image = reader.read(); + painter.drawImage(0, 0, image); // xi, yi is the position for imagei +// if (counter == 0) +// { +// base = QImage(bg.size(), QImage::Format_ARGB32_Premultiplied); +// qDebug() << "FIIIRST "; + +// } +// else +// { + +// } + qDebug() << "iterating through QVariantList "; + qDebug() << (*j).toString(); // Print QVariant + counter++; + } + painter.end(); + + // Transform image into PNG format + QByteArray ba; + QBuffer buffer( &ba ); + buffer.open( QIODevice::WriteOnly ); + result.save( &buffer, "png" ); + + // Get Based 64 image string + QString encoded = QString(ba.toBase64()); + + qDebug() << "@@@@@ encoded avatar " << encoded ; + return encoded; } + + QImage getImageFromPath (QString localPath) + { + qDebug() << "getImageFromPath() local path:" << localPath ; + + // Read the image + QImageReader reader; + reader.setFileName(localPath); + QImage image = reader.read(); + return image; + + } + + }; diff --git a/retroshare-qml-app/src/components/Faces.qml b/retroshare-qml-app/src/components/Faces.qml index f814ebb6d..ed60df314 100644 --- a/retroshare-qml-app/src/components/Faces.qml +++ b/retroshare-qml-app/src/components/Faces.qml @@ -19,43 +19,43 @@ Item visible: true } - Canvas - { - id: canvasAvatar - width: height - height: canvasSizes - visible: false +// Canvas +// { +// id: canvasAvatar +// width: height +// height: canvasSizes +// visible: false - renderStrategy: Canvas.Threaded; - renderTarget: Canvas.Image; +// renderStrategy: Canvas.Threaded; +// renderTarget: Canvas.Image; - property var images - property var callback +// property var images +// property var callback - onPaint: - { - var ctx = getContext("2d"); +// onPaint: +// { +// var ctx = getContext("2d"); - if (images) - { - for (y = 0 ; y< nPieces ; y++) - { - ctx.drawImage(images[y], 0, 0, iconSize, iconSize ) - } - } +// if (images) +// { +// for (y = 0 ; y< nPieces ; y++) +// { +// ctx.drawImage(images[y], 0, 0, iconSize, iconSize ) +// } +// } - } +// } - onPainted: - { - if (callback) - { - var data = toDataURL('image/png') - callback(data) - } - } - } +// onPainted: +// { +// if (callback) +// { +// var data = toDataURL('image/png') +// callback(data) +// } +// } +// } Component.onCompleted: { @@ -134,11 +134,14 @@ Item { var url = src(gender, i, data[i+1]) onloads.push(url) - canvasAvatar.loadImage(url) +// canvasAvatar.loadImage(url) } - canvasAvatar.images = onloads - canvasAvatar.callback = callback - canvasAvatar.requestPaint() +// canvasAvatar.images = onloads +// canvasAvatar.callback = callback + var datas = androidImagePicker.faceImage(onloads, iconSize) + console.log("@@@@@@@ url " , datas) + callback("data:image/png;base64,"+datas) +// canvasAvatar.requestPaint() } // Create the identicon @@ -156,17 +159,17 @@ Item { imageAvatar.source = data imageAvatar.visible = true - canvasAvatar.visible = false +// canvasAvatar.visible = false - canvasAvatar.height = 0 +// canvasAvatar.height = 0 imageAvatar.height = iconSize } else { - canvasAvatar.visible = true +// canvasAvatar.visible = true imageAvatar.visible = false - canvasAvatar.height = iconSize +// canvasAvatar.height = iconSize imageAvatar.height = 0 }