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. what is the best way to open various kind formats of images with Qt?

what is the best way to open various kind formats of images with Qt?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.4k Views 3 Watching
  • 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.
  • O Offline
    O Offline
    opengpu2
    wrote on last edited by
    #1

    what is the best way to open various kind formats of images with Qt?
    QImage, or QPixmap?
    and how can i know i open the image file correctly?
    i found there is no open() API, just set the file path in the constructor.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      It depends on what you want to do with the image data. You can use isNull to know whether your QImage/QPixmap is correctly loaded.

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

      O 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        It depends on what you want to do with the image data. You can use isNull to know whether your QImage/QPixmap is correctly loaded.

        O Offline
        O Offline
        opengpu2
        wrote on last edited by
        #3

        @SGaist i use the return bool of load()
        is this the same?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          If load returns falls, then yes your QImage will be null

          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
          • L Offline
            L Offline
            LuGRU
            wrote on last edited by
            #5

            Difference between classes: http://doc.qt.io/qt-5/qpixmap.html#details

            In nutshell
            QImage - for access, passing image data across threads, accessing pixel data
            QPixmap - display - OGL / Shaders / Rester - usually data resides on Server side (depending on platform etc. it can mean GPU memory if hw acceleration is used)

            To know if image can be read use: bool QImageReader::canRead() const

            Both classes are just containers for data and do not support by themselves file formates. To get a list of supported file formats for i.e. reading use QImageReader::supportedImageFormats() (QImageWriter for writing). To add new file format support one need to write plugin to extend supported formats.

            Both classes have isNull() method that can be checked after loading if image data is loaded.
            There is also QImageReader class http://doc.qt.io/qt-4.8/qimagereader.html

            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