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. How to save images in a different format
Forum Updated to NodeBB v4.3 + New Features

How to save images in a different format

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 5 Posters 916 Views 2 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.
  • K Offline
    K Offline
    kosai
    wrote on last edited by
    #1

    Hi everyone!
    my problem is that i am using 'save(const QString&, const char*)' function to save the image in another format but it doesn't work properly !
    the difference between the original and the save image is obviouse but the extention still the same!!
    i have a problem on my computer or i didn't understand what the 'save' function does??

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

      Hi and welcome to devnet,

      What code are you using ?
      What version of Qt are you using ?
      What OS are you running ?
      What compiler are you using ?
      What image format do you have as input ?
      What image format are you trying to have as output ?
      What is the exact error you have ?
      What output are you expecting ?
      What output are you getting ?

      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
      • K Offline
        K Offline
        kosai
        wrote on last edited by
        #3

        i am programming in C++ language , Qt 4.11.1 , on Windows 7, i am using Qt 5.14.2 MinGW 64 bit, input format (png, jpg, jpeg, gif), just(jpeg) as output, i did not have error or either warning , images are being saved succecfully but its not changing the format !

        jsulmJ 1 Reply Last reply
        0
        • K kosai

          i am programming in C++ language , Qt 4.11.1 , on Windows 7, i am using Qt 5.14.2 MinGW 64 bit, input format (png, jpg, jpeg, gif), just(jpeg) as output, i did not have error or either warning , images are being saved succecfully but its not changing the format !

          jsulmJ Online
          jsulmJ Online
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @kosai Please show your code

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kosai
            wrote on last edited by
            #5
            void Mwindow::NvlElem(void)
            {
                QDir::setCurrent(m_ImgDir);//setting the Directory file
                if(!Line->text().isEmpty())
                {
                    //if user write name of object
                    //List->addItem(Line->text());
                    List->addItem(Line->text());
                    //**
                    if(List->count() == 1)
                        List->setCurrentRow(0);
                    return;
                }
            
                //get Image
                QString ImgDir = QFileDialog::getOpenFileName(this,
                                                             "Ouvrir un fichier",
                                                             QString(),
                                                             "Images (*.png *.gif *.jpg *.jpeg)");
                //--Display Img on Tab
                ImgPixmap->load(ImgDir);
                ImgWin->setPixmap(*ImgPixmap);
                //--save Img in Items
                Image->load(ImgDir);
                QString ImgExt(ImgDir.right(4)), RImgName, ImgName;
                if(ImgExt[0] != ".")
                    ImgExt = ImgDir.right(5);
                //get extention
                //--i did not find a better way to get extention !
                for (int i(ImgDir.length()); i >= 0; i--) {
                    if(ImgDir[i] == "/")
                        break;
                    RImgName += ImgDir[i];
                }
                for(int i(RImgName.length()-1); i >= 0; i--) {
                    if(RImgName[i] == ".")
                        break;
                    ImgName += RImgName[i];
                }
                //--here is the prblm !!!!
                if(Image->save(ImgName+ImgExt, "png"))
                {
                    List->addItem(ImgName);
                }
                //*
                if(List->count() == 1)
                    List->setCurrentRow(0);
            //*****tring another way  using QImageWriter but it doesnt work either!
                ImgWriter->setFileName(ImgName);
                Line->setText(ImgWriter->fileName());
            }
            
            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              The format is 'PNG', not 'png'.
              The extension can be retrieved via QFileInfo and there is no need to create a QImage with new.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              2
              • K Offline
                K Offline
                kosai
                wrote on last edited by
                #7

                ok!
                i tried "PNG" its the same problem !

                jsulmJ 1 Reply Last reply
                0
                • K kosai

                  ok!
                  i tried "PNG" its the same problem !

                  jsulmJ Online
                  jsulmJ Online
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by jsulm
                  #8

                  @kosai In your first post you wrote: "but the extention still the same". This is a different problem than "but its not changing the format". So, did you make sure the format was indeed not changed?

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    kosai
                    wrote on last edited by
                    #9

                    the problem is a little bit bizzard !
                    it's like changing bytes into the desired format --> if you put saved image with the original you will distinguish the diffrence !
                    but unlike if you go to the file on the desktop the extention doesn't change at all !!
                    i hope this helps to understand my problem?

                    jsulmJ J.HilkJ 2 Replies Last reply
                    0
                    • K kosai

                      the problem is a little bit bizzard !
                      it's like changing bytes into the desired format --> if you put saved image with the original you will distinguish the diffrence !
                      but unlike if you go to the file on the desktop the extention doesn't change at all !!
                      i hope this helps to understand my problem?

                      jsulmJ Online
                      jsulmJ Online
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by jsulm
                      #10

                      @kosai said in How to save images in a different format:

                      i hope this helps to understand my problem?

                      Not really.
                      What exactly is the problem:

                      • Wrong file extension?
                      • File is not stored as png?

                      Please be more clear.
                      If the file extension is not what you want then check your code and use @Christian-Ehrlicher suggested to get file extension.

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • K kosai

                        the problem is a little bit bizzard !
                        it's like changing bytes into the desired format --> if you put saved image with the original you will distinguish the diffrence !
                        but unlike if you go to the file on the desktop the extention doesn't change at all !!
                        i hope this helps to understand my problem?

                        J.HilkJ Online
                        J.HilkJ Online
                        J.Hilk
                        Moderators
                        wrote on last edited by
                        #11

                        @kosai said in How to save images in a different format:

                        ile on the desktop the extention doesn't change at all !!

                        why should the extension change ? you extract it from the select file

                        QString ImgExt(ImgDir.right(4)), RImgName, ImgName;
                            if(ImgExt[0] != ".")
                                ImgExt = ImgDir.right(5);
                        

                        and than append it again to the filename when you save it

                        Image->save(ImgName+ImgExt, "png")
                        

                        without changing it in-between, of course it will have the same extension.


                        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                        Q: What's that?
                        A: It's blue light.
                        Q: What does it do?
                        A: It turns blue.

                        1 Reply Last reply
                        4
                        • K Offline
                          K Offline
                          kosai
                          wrote on last edited by
                          #12

                          yeah! you are right i shouldn't put the original extention with the name !
                          thank you everyone !

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

                            Another issue in your code, why are you forcing the output to be PNG and yet allow other extensions ? That does not really make sense. Personally I would be very surprised to find PNG while opening for example a .bmp file.

                            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

                            • Login

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