Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Get Image from Iphone library
Forum Updated to NodeBB v4.3 + New Features

Get Image from Iphone library

Scheduled Pinned Locked Moved Solved Mobile and Embedded
iphoneiosimagemfiledialog
2 Posts 1 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    renatobibiano
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • R Offline
      R Offline
      renatobibiano
      wrote on last edited by
      #2

      found the answer in: https://forum.qt.io/topic/47495/upload-ios-image-with-qt/8

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved