Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Loading DDS file to QImage from raw data

    General and Desktop
    3
    7
    2808
    Loading More Posts
    • 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.
    • S
      Spook last edited by

      Hello,
      I would like to read a DDS file from an archive and show it using a QImage. I already have the code that is able to get the file contents from the zip file done, but for now I extracted the DDS file to a folder and am reading it from there.
      As I'm quite new to Qt, I'm using very simple code for now:

      int main(int argc, char *argv[])
      {
      	QApplication app(argc, argv);
      	QFile file("helm.dds");
      	QByteArray bArray = file.readAll();
      	QImage image = QImage::fromData(bArray);//myImage.copy(0, 84, 102, 84).scaled(50, 50); //copying a part of the texture then reducing its size
      	QLabel label;
      	label.setPixmap(QPixmap::fromImage(image));
      	label.show();
      	return app.exec();
      }	
      

      This code compiles, I don't have any issue with it.
      The problem comes from QImage::fromData. I'm not able to use "DDS" as the format as it's not supported, so I was wondering if there was any other alternative?
      Thank you!

      1 Reply Last reply Reply Quote 0
      • ?
        A Former User last edited by

        Hi! You could you imagemagick to convert the DDS to PNG. You could do this either by calling the executable convert that comes with imagemagick or you could use imagemagick's C or C++ interface.

        S 1 Reply Last reply Reply Quote 0
        • S
          Spook @Guest last edited by Spook

          Hi, thank you for your reply!
          ImageMagick++ does not seem to do what I'm looking for unfortunately.
          I'd like to read / convert everything from memory instead of creating new files. So, read the DDS file in memory, (convert it to some other format if needed) load it into a QImage from a QByteArray (not necessarily a QByteArray though, but something that doesn't require me to create a new file).

          1 Reply Last reply Reply Quote 0
          • ?
            A Former User last edited by

            Temporary files e.g. in /var/tmp aren't an option for you?

            1 Reply Last reply Reply Quote 0
            • S
              Spook last edited by

              I've never used temporary files, but I did think of them as a last option if nothing else can help.

              1 Reply Last reply Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by SGaist

                Hi and welcome to devnet,

                What version of Qt are you using ? DDS is listed in the supported QImage formats

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply Reply Quote 0
                • ?
                  A Former User last edited by

                  Yes, @SGaist is right; at least here with Qt 5.5.1 it works:

                      const QString fileName("/home/pw/0.dds");
                      const QPixmap pixmap(fileName);
                      ui->label->setPixmap(pixmap);
                  
                      const QImage image = pixmap.toImage();
                      qDebug() << (image.isNull() ? "QImage error" : "QImage ok");
                  
                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post