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

THREE.TextureLoader load the image fail with imageprovider



  • in my main.cpp

    QQmlApplicationEngine engine;
    engine.addImageProvider("imageProvider", imageProvider);
    

    then i can use image in my qml like this(it run ok):

            Image {
                    id: zoomout_img
                    source: "image://imageProvider/map.png"                    
                }
    

    also I use threejs in my code like this(it run ok) :

    var geometry = new THREE.PlaneGeometry( 0.4, 0.4, 0.4, 0.4 );
    var textureLoader = new THREE.TextureLoader();
    var textureCase= textureLoader.load("qrc:/img/xxx.png");
    var material = new THREE.MeshBasicMaterial({ map: textureCase , transparent: true});
    var mesh = new THREE.Mesh( geometry, material );
    

    however,when i load image by imageprovider,it fail:

    var geometry = new THREE.PlaneGeometry( 0.4, 0.4, 0.4, 0.4 );
    var textureLoader = new THREE.TextureLoader();
    var textureCase= textureLoader.load("image://imageProvider/map.png");
    var material = new THREE.MeshBasicMaterial({ map: textureCase , transparent: true});
    var mesh = new THREE.Mesh( geometry, material );
    

    any one know why?the image provider is like this:

    class BkgImgProvider : public QQuickImageProvider
    {
    public:
        explicit BkgImgProvider():QQuickImageProvider(QQuickImageProvider::Pixmap){
    
        }
        virtual QPixmap requestPixmap(const QString &id, QSize *size, const QSize& requestedSize)
        {
            QImage img;
            if(id == "map.png")
                img = QImage::fromData(qba_map,format.toStdString().c_str());
    
            if(!img.isNull()){
                if (requestedSize.isValid()) {
                    img.scaledToWidth(requestedSize.width());
                    img.scaledToHeight(requestedSize.height());
                }else{
                    //                    img.scaledToWidth(bkg->getWidth());
                    //                    img.scaledToHeight(bkg->getHeight());
                }
                *size = img.size();
            }
    
            QPixmap pix = QPixmap::fromImage(img);
            return pix;
        }
        void setMapData(const QByteArray &qba){qba_map = qba;};
    private:
        QByteArray qba_map;
    }

Log in to reply