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 <QBuffer>
#include "qpainter.h"
#ifdef __ANDROID__
# include <QtAndroid>
@ -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;
}
};

View File

@ -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
}