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. Quality of scaled Pixmaps
Forum Updated to NodeBB v4.3 + New Features

Quality of scaled Pixmaps

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 4 Posters 2.9k Views 1 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.
  • T Offline
    T Offline
    TauCeti
    wrote on last edited by
    #1

    Hi,
    the quality of a scaled png image seems to be very bad, especially if there is
    text in the image. This is the case, even if the size of the original image is the same as the scaled image.

    The image is scaled in this way:

    QPixmap image(path);
    int h = ui.picturePlaceholder->height();
    int w = ui.picturePlaceholder->width(); 
    QLabel *ui.image;
    ui.image->setPixmap(image.scaled(w, h, Qt::KeepAspectRatio));
    

    I tried to optimize the resolution of the original image before scaling.
    Is there a way to improve the quality of the image for the scaling or fitting process?
    What could be responsible for the bad quality?

    Thanks for help.

    artwawA 1 Reply Last reply
    0
    • T TauCeti

      Hi,
      the quality of a scaled png image seems to be very bad, especially if there is
      text in the image. This is the case, even if the size of the original image is the same as the scaled image.

      The image is scaled in this way:

      QPixmap image(path);
      int h = ui.picturePlaceholder->height();
      int w = ui.picturePlaceholder->width(); 
      QLabel *ui.image;
      ui.image->setPixmap(image.scaled(w, h, Qt::KeepAspectRatio));
      

      I tried to optimize the resolution of the original image before scaling.
      Is there a way to improve the quality of the image for the scaling or fitting process?
      What could be responsible for the bad quality?

      Thanks for help.

      artwawA Offline
      artwawA Offline
      artwaw
      wrote on last edited by
      #2

      @TauCeti said in Quality of scaled Pixmaps:

      ui.image->setPixmap(image.scaled(w, h, Qt::KeepAspectRatio));

      Try ui.image->setPixmap(image.scaled(w,h,Qt::KeepAspectRatio,Qt::SmoothTransformation));

      For more information please re-read.

      Kind Regards,
      Artur

      T 1 Reply Last reply
      2
      • artwawA artwaw

        @TauCeti said in Quality of scaled Pixmaps:

        ui.image->setPixmap(image.scaled(w, h, Qt::KeepAspectRatio));

        Try ui.image->setPixmap(image.scaled(w,h,Qt::KeepAspectRatio,Qt::SmoothTransformation));

        T Offline
        T Offline
        TauCeti
        wrote on last edited by
        #3

        @artwaw said in Quality of scaled Pixmaps:

        Try ui.image->setPixmap(image.scaled(w,h,Qt::KeepAspectRatio,Qt::SmoothTransformation));

        Thanks, this a step in the correct direction. It improves lines and borders in the image..
        The text is improved at some positions, at some other positions its worse.

        Is the png format the problem?

        artwawA JoeCFDJ 2 Replies Last reply
        0
        • T TauCeti

          @artwaw said in Quality of scaled Pixmaps:

          Try ui.image->setPixmap(image.scaled(w,h,Qt::KeepAspectRatio,Qt::SmoothTransformation));

          Thanks, this a step in the correct direction. It improves lines and borders in the image..
          The text is improved at some positions, at some other positions its worse.

          Is the png format the problem?

          artwawA Offline
          artwawA Offline
          artwaw
          wrote on last edited by
          #4

          @TauCeti should not be, raster is raster and png compression should not affect (unlike certain jpg compression parameters). From my experience problem almost every time lies in the size/quality of the source image (I did render A5 pdf files into raster image, lot's of fun)

          For more information please re-read.

          Kind Regards,
          Artur

          1 Reply Last reply
          1
          • T TauCeti

            @artwaw said in Quality of scaled Pixmaps:

            Try ui.image->setPixmap(image.scaled(w,h,Qt::KeepAspectRatio,Qt::SmoothTransformation));

            Thanks, this a step in the correct direction. It improves lines and borders in the image..
            The text is improved at some positions, at some other positions its worse.

            Is the png format the problem?

            JoeCFDJ Offline
            JoeCFDJ Offline
            JoeCFD
            wrote on last edited by JoeCFD
            #5

            @TauCeti it is a problem. Use svg format which keeps the resolution of the image in scaling.

            T artwawA 2 Replies Last reply
            0
            • JoeCFDJ JoeCFD

              @TauCeti it is a problem. Use svg format which keeps the resolution of the image in scaling.

              T Offline
              T Offline
              TauCeti
              wrote on last edited by TauCeti
              #6

              @JoeCFD said in Quality of scaled Pixmaps:

              @TauCeti it is a problem. Use svg format which keeps the resolution of the image in scaling.

              I will try this also. Can you help me with the correct way of implementing a svg? As I remember it can not be used with a QLabel.

              1 Reply Last reply
              0
              • JoeCFDJ JoeCFD

                @TauCeti it is a problem. Use svg format which keeps the resolution of the image in scaling.

                artwawA Offline
                artwawA Offline
                artwaw
                wrote on last edited by
                #7

                @JoeCFD OP asked about bitmaps/rasters not vectors.

                @TauCeti Details on SVG are here: https://doc.qt.io/qt-5/svgrendering.html

                For that distorted bitmap of yours, are you sure you are not upscaling? If you enlarge bitmaps distortion is rather... inevitable.

                For more information please re-read.

                Kind Regards,
                Artur

                1 Reply Last reply
                4
                • nageshN Offline
                  nageshN Offline
                  nagesh
                  wrote on last edited by
                  #8

                  @TauCeti said in Quality of scaled Pixmaps:

                  ui.image->setPixmap(image.scaled(w, h, Qt::KeepAspectRatio));

                  4th arguement to scaled function can be passed as Qt::SmoothTransformation

                  even if the size of the original image is the same as the scaled image.
                  

                  get the original image size and check with placeholder size, @artwaw pointed out you might be doing image upscaling.

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    TauCeti
                    wrote on last edited by
                    #9

                    Thanks, there was indeed an upscaling of a few pixels. In combination with SmoothTransformation it looks good now.

                    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