mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Scale image before base64 encoding
This commit is contained in:
parent
938c3109f6
commit
875b625abb
@ -9,6 +9,7 @@
|
|||||||
#include <QImageReader>
|
#include <QImageReader>
|
||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
|
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
# include <QtAndroid>
|
# include <QtAndroid>
|
||||||
# include <QtAndroidExtras/QAndroidJniObject>
|
# include <QtAndroidExtras/QAndroidJniObject>
|
||||||
@ -39,21 +40,25 @@ public slots:
|
|||||||
QUrl url (path);
|
QUrl url (path);
|
||||||
QString localPath = url.toLocalFile();
|
QString localPath = url.toLocalFile();
|
||||||
|
|
||||||
|
qDebug() << "imageToBase64() local path:" << localPath ;
|
||||||
|
|
||||||
// Read the image
|
// Read the image
|
||||||
QImageReader reader;
|
QImageReader reader;
|
||||||
reader.setFileName(localPath);
|
reader.setFileName(localPath);
|
||||||
QImage image = reader.read();
|
QImage image = reader.read();
|
||||||
|
|
||||||
|
image = image.scaled(96,96,Qt::KeepAspectRatio,Qt::SmoothTransformation);
|
||||||
|
|
||||||
// Transform image into PNG format
|
// Transform image into PNG format
|
||||||
QByteArray ba;
|
QByteArray ba;
|
||||||
QBuffer buffer( &ba );
|
QBuffer buffer( &ba );
|
||||||
buffer.open( QIODevice::WriteOnly );
|
buffer.open( QIODevice::WriteOnly );
|
||||||
image.save( &buffer, "PNG" );
|
image.save( &buffer, "png" );
|
||||||
|
|
||||||
// Get Based 64 image string
|
// Get Based 64 image string
|
||||||
QString encoded = QString(ba.toBase64());
|
QString encoded = QString(ba.toBase64());
|
||||||
|
|
||||||
qDebug() << "imageToBase64() " ;
|
qDebug() << "imageToBase64() " << encoded ;
|
||||||
|
|
||||||
return encoded;
|
return encoded;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user