mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-16 01:47:17 -05:00
Function to convert an image to a png base64 format
This commit is contained in:
parent
0494dd7516
commit
c570aae9f7
@ -3,6 +3,12 @@
|
||||
#include <QObject>
|
||||
#include <QDebug>
|
||||
|
||||
#include <QFile>
|
||||
#include <QUrl>
|
||||
#include <QImage>
|
||||
#include <QImageReader>
|
||||
#include <QBuffer>
|
||||
|
||||
#ifdef __ANDROID__
|
||||
# include <QtAndroid>
|
||||
# include <QtAndroidExtras/QAndroidJniObject>
|
||||
@ -18,10 +24,38 @@ public slots:
|
||||
{
|
||||
qDebug() << "Starting image picker intent";
|
||||
|
||||
#ifdef __ANDROID__
|
||||
QtAndroid::androidActivity().callMethod<void>(
|
||||
"openImagePicker",
|
||||
"()V" );
|
||||
#endif // __ANDROID__
|
||||
#ifdef __ANDROID__
|
||||
QtAndroid::androidActivity().callMethod<void>(
|
||||
"openImagePicker",
|
||||
"()V" );
|
||||
#endif // __ANDROID__
|
||||
|
||||
}
|
||||
|
||||
// Used to convert a given image path into a png base64 string
|
||||
static QString imageToBase64 (QString const& path)
|
||||
{
|
||||
// Get local path from uri
|
||||
QUrl url (path);
|
||||
QString localPath = url.toLocalFile();
|
||||
|
||||
// Read the image
|
||||
QImageReader reader;
|
||||
reader.setFileName(localPath);
|
||||
QImage image = reader.read();
|
||||
|
||||
// Transform image into PNG format
|
||||
QByteArray ba;
|
||||
QBuffer buffer( &ba );
|
||||
buffer.open( QIODevice::WriteOnly );
|
||||
image.save( &buffer, "PNG" );
|
||||
|
||||
// Get Based 64 image string
|
||||
QString encoded = QString(ba.toBase64());
|
||||
|
||||
qDebug() << "imageToBase64() " ;
|
||||
|
||||
return encoded;
|
||||
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user