Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Image saved to picture but return false



  • i got problem so crazy
    first i take picture by camera in qml them store it to image. Then i used graptoimage to save this picture to disk but file it saved in Pictures folder (default folder of ubuntu ) in different name, look like "IMG_00000001.jpg"
    here 2 part of code

    qml

    console.log("grab to image")
                imagePreview.grabToImage(function(result){
                    control.cvtImg2Base64(result);
                })
    

    c++

    QString MainControl::cvtImg2Base64(QVariant var)
    {
        qDebug()<<Q_FUNC_INFO;
        QImage img = qvariant_cast<QImage>(var);
        qDebug()<<img.save("/home/ryu/Pictures/ryu.jpg"); //return false
        QPixmap pix = QPixmap::fromImage(img);
        qDebug()<<pix.save("/home/ryu/Pictures/shai.jpg"); //return false
    

    anyone can explain for me WHY ?



  • https://doc.qt.io/qt-5/qml-qtquick-itemgrabresult.html#image-prop

    console.log("grab to image")
                imagePreview.grabToImage(function(result){
                    control.cvtImg2Base64(result.image);
                })
    
    QString MainControl::cvtImg2Base64(QImage img)
    {
        qDebug()<<Q_FUNC_INFO;
        qDebug()<<img.save("/home/ryu/Pictures/ryu.jpg");
        QPixmap pix = QPixmap::fromImage(img);
        qDebug()<<pix.save("/home/ryu/Pictures/shai.jpg");
    }
    

Log in to reply