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. Can Qt Convert jpg images to the BMP format?
QtWS25 Last Chance

Can Qt Convert jpg images to the BMP format?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 9.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.
  • R Offline
    R Offline
    redstoneleo
    wrote on last edited by A Former User
    #1

    Can Qt Convert jpg images to the BMP format? If possible ,please give a little code,thanks .

    tried

    QImage('C:\\0dbcaadd144059fd76c6388a.jpg').save('C:\\2.jpg',"BMP")
    

    but just return False, anyone know why ?

    Googled, but not find an answer .

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by A Former User
      #2
      QPixmap pix("path-to/image.jpg");
      pix.save("path-to/image.bmp");
      

      Also see this

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by A Former User
        #3

        Hi,

        Something like:

        QImage myJpgImage("path_to_jpeg.jpg");
        qDebug() << myJpgImage.save("path_to_bitmap.bmp");
        

        ?

        More information in the QImage documentation here and here

        [edit: it's been a long time since synchronous posting raven-worx :D]

        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
        • R Offline
          R Offline
          redstoneleo
          wrote on last edited by
          #4

          tried
          @
          QImage('C:\0dbcaadd144059fd76c6388a.jpg').save('C:\2.jpg',"BMP")
          @
          but just return False, anyone know why ?
          [quote author="SGaist" date="1421848773"]Hi,

          Something like:

          @
          QImage myJpgImage("path_to_jpeg.jpg");
          qDebug() << myJpgImage.save("path_to_bitmap.bmp");
          @

          ?

          More information in the QImage documentation "here":http://doc.qt.io/qt-5/qimage.html#reading-and-writing-image-files and "here":http://doc.qt.io/qt-5/qimage.html#save

          [edit: it's been a long time since synchronous posting raven-worx :D][/quote]

          1 Reply Last reply
          0
          • R Offline
            R Offline
            redstoneleo
            wrote on last edited by
            #5

            Have you tried it ? save() just return false
            [quote author="raven-worx" date="1421848703"]@
            QPixmap pix("path-to/image.jpg");
            pix.save("path-to/image.bmp");
            @

            Also see "this":http://doc.qt.io/qt-5/qtimageformats-index.html[/quote]

            1 Reply Last reply
            0
            • raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              [quote author="SGaist" date="1421848773"]
              [edit: it's been a long time since synchronous posting raven-worx :D]
              [/quote]
              yep! i was quite busy the last year :)

              [quote author="redstoneleo" date="1421850868"]Have you tried it ? save() just return false[/quote]
              more than once, yes :)

              ok lets try something else then. What does the following return?
              @
              QImageWriter::supportedImageFormats();
              @
              If the list contains "BMP" you should check if you are allowed to read/write the image files from/to the path you've specified.

              Also you should avoid something like this:
              @
              QImage('C:\0dbcaadd144059fd76c6388a.jpg').save('C:\2.jpg',"BMP")
              @
              Qt automatically checks the file extension and chooses the right "codec" to write the image.

              Edit: I am also not quite sure if it is allowed to write to "C:" in all cases (e.g. when you don't run the application as Administrator for example)

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

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

                To add to raven-worx, the file extension is the first thing checked, if Qt doesn't find a corresponding encoder, it's use the second parameter as a hint.

                Also, you can use unix's forward slash notation with Qt, so you don't take the risk of messing your path because you forgot a double backslash.

                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
                • R Offline
                  R Offline
                  redstoneleo
                  wrote on last edited by
                  #8

                  The reason why it didn't work before is I changed the image's suffix from jpg to bmp subjectively,then use QImage::​save() to convert format to bmp, thus it faild, after correct this mistake ,it worked now!

                  BTW,for
                  @bool QImage::​save(const QString & fileName, const char * format = 0, int quality = -1) const@
                  If format is 0, QImage will attempt to guess the format by looking at fileName's suffix,so format is prior to fileName's suffix.

                  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