Encode base64 via c++ code

This commit is contained in:
Angela Mazzurco 2017-09-07 20:30:08 +02:00
parent 404469b0a7
commit 75180f2a01
2 changed files with 101 additions and 38 deletions

View File

@ -9,6 +9,8 @@
#include <QImageReader> #include <QImageReader>
#include <QBuffer> #include <QBuffer>
#include "qpainter.h"
#ifdef __ANDROID__ #ifdef __ANDROID__
# include <QtAndroid> # include <QtAndroid>
@ -60,7 +62,65 @@ public slots:
qDebug() << "imageToBase64() encoded" ; 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; 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;
}
}; };

View File

@ -19,43 +19,43 @@ Item
visible: true visible: true
} }
Canvas // Canvas
{ // {
id: canvasAvatar // id: canvasAvatar
width: height // width: height
height: canvasSizes // height: canvasSizes
visible: false // visible: false
renderStrategy: Canvas.Threaded; // renderStrategy: Canvas.Threaded;
renderTarget: Canvas.Image; // renderTarget: Canvas.Image;
property var images // property var images
property var callback // property var callback
onPaint: // onPaint:
{ // {
var ctx = getContext("2d"); // var ctx = getContext("2d");
if (images) // if (images)
{ // {
for (y = 0 ; y< nPieces ; y++) // for (y = 0 ; y< nPieces ; y++)
{ // {
ctx.drawImage(images[y], 0, 0, iconSize, iconSize ) // ctx.drawImage(images[y], 0, 0, iconSize, iconSize )
} // }
} // }
} // }
onPainted: // onPainted:
{ // {
if (callback) // if (callback)
{ // {
var data = toDataURL('image/png') // var data = toDataURL('image/png')
callback(data) // callback(data)
} // }
} // }
} // }
Component.onCompleted: Component.onCompleted:
{ {
@ -134,11 +134,14 @@ Item
{ {
var url = src(gender, i, data[i+1]) var url = src(gender, i, data[i+1])
onloads.push(url) onloads.push(url)
canvasAvatar.loadImage(url) // canvasAvatar.loadImage(url)
} }
canvasAvatar.images = onloads // canvasAvatar.images = onloads
canvasAvatar.callback = callback // canvasAvatar.callback = callback
canvasAvatar.requestPaint() var datas = androidImagePicker.faceImage(onloads, iconSize)
console.log("@@@@@@@ url " , datas)
callback("data:image/png;base64,"+datas)
// canvasAvatar.requestPaint()
} }
// Create the identicon // Create the identicon
@ -156,17 +159,17 @@ Item
{ {
imageAvatar.source = data imageAvatar.source = data
imageAvatar.visible = true imageAvatar.visible = true
canvasAvatar.visible = false // canvasAvatar.visible = false
canvasAvatar.height = 0 // canvasAvatar.height = 0
imageAvatar.height = iconSize imageAvatar.height = iconSize
} }
else else
{ {
canvasAvatar.visible = true // canvasAvatar.visible = true
imageAvatar.visible = false imageAvatar.visible = false
canvasAvatar.height = iconSize // canvasAvatar.height = iconSize
imageAvatar.height = 0 imageAvatar.height = 0
} }