Get Image from Iphone library
Solved
Mobile and Embedded
-
Hi all!
I have an application that should get imagem from a library and save it to my database. Everything works fine on my mac. But, when I try to run it on my iphone, it can't find the image I guess. The return from the FileDialog is:
file:assets-library:/asset/asset.JPG%3Fid=F6BD4B3D-CF6B-4A64-8C9E-6C28583DE80F&ext=JPG
Really strange to me.
My QML code is really simple:
FileDialog { id: fileDialog title: "Please choose a file" folder: shortcuts.pictures onSelectionAccepted: { console.log("You chose: " + fileDialog.fileUrl); img.source = fileDialog.fileUrl; } onRejected: { console.log("Canceled"); } }
And my c++ code is:
QString ImageCropper::cropImage(const QString &id, int x, int y, int width, int height) { QString str(id); #ifdef Q_OS_IOS str.remove(0,5); #else str.remove(0,7); #endif QImage rawImage(str); int value = 0; float proportion = 0.0; if(rawImage.size().width() <= rawImage.size().height()) { proportion = rawImage.size().width()/(float)width; value = rawImage.size().width(); } else { proportion = rawImage.size().height()/(float)height; value = rawImage.size().height(); } QImage maskedImage(QSize(value, value), QImage::Format_ARGB32_Premultiplied); if (!rawImage.isNull()) { QPainterPath path; path.addRect( QRect(0, 0, value, value)); QPainter m_ctx; m_ctx.begin(&maskedImage); m_ctx.setClipping(true); m_ctx.setClipPath(path); m_ctx.drawImage(QPoint(-x*proportion, -y*proportion), rawImage); m_ctx.end(); maskedImage.save(QDir::homePath()+"/Pictures/profilePicture.jpg"); QByteArray ba; QBuffer buffer(&ba); buffer.open(QIODevice::WriteOnly); maskedImage.save(&buffer, "JPG"); return QString(ba.toBase64()); } }
Hope you guys can help me.
Regards,
Renato. -
found the answer in: https://forum.qt.io/topic/47495/upload-ios-image-with-qt/8