Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Loading DDS file to QImage from raw data
QtWS25 Last Chance

Loading DDS file to QImage from raw data

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 3.5k 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.
  • S Offline
    S Offline
    Spook
    wrote on last edited by
    #1

    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
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      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
      0
      • ? A Former User

        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 Offline
        S Offline
        Spook
        wrote on last edited by Spook
        #3

        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
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Spook
            wrote on last edited by
            #5

            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
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by SGaist
              #6

              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
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

                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
                0

                • Login

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