Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. THREE.TextureLoader load the image fail with imageprovider
Qt 6.11 is out! See what's new in the release blog

THREE.TextureLoader load the image fail with imageprovider

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 562 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.
  • Q Offline
    Q Offline
    qintxwd
    wrote on last edited by
    #1

    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;
    }
    
    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