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. Pixel stretched when zooming QImage a lot
Qt 6.11 is out! See what's new in the release blog

Pixel stretched when zooming QImage a lot

Scheduled Pinned Locked Moved Solved General and Desktop
18 Posts 5 Posters 1.7k 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.
  • Christian EhrlicherC Christian Ehrlicher

    @Mwoua said in Pixel stretched when zooming QImage a lot:

    expect all pixels to have the same size,

    How should this work with FastTransformation?

    M Offline
    M Offline
    Mwoua
    wrote on last edited by
    #9

    @Christian-Ehrlicher I dont really know what fasttransformation does. It says " The transformation is performed quickly, with no smoothing." So I dont know what is the expected result

    I don't think I really need smoothing, it's probably just a rounding error or something like that. Hence why I am asking about alternatives

    Christian EhrlicherC 1 Reply Last reply
    0
    • M Mwoua

      @Christian-Ehrlicher I dont really know what fasttransformation does. It says " The transformation is performed quickly, with no smoothing." So I dont know what is the expected result

      I don't think I really need smoothing, it's probably just a rounding error or something like that. Hence why I am asking about alternatives

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #10

      @Mwoua said in Pixel stretched when zooming QImage a lot:

      So I dont know what is the expected result

      Nothing expensive is done so the only way to do is, is to duplicate some rows / columns.

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

      M 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        @Mwoua said in Pixel stretched when zooming QImage a lot:

        So I dont know what is the expected result

        Nothing expensive is done so the only way to do is, is to duplicate some rows / columns.

        M Offline
        M Offline
        Mwoua
        wrote on last edited by Mwoua
        #11

        @Christian-Ehrlicher Ok, thanks for the info, thats good to know.

        Is Qt::SmoothTransformation the only alternative?

        B 1 Reply Last reply
        0
        • M Mwoua

          @Christian-Ehrlicher Ok, thanks for the info, thats good to know.

          Is Qt::SmoothTransformation the only alternative?

          B Offline
          B Offline
          Bonnie
          wrote on last edited by Bonnie
          #12

          @Mwoua :

          Is Qt::SmoothTransformation the only alternative?

          For transformMode, yes.
          Aren't you expecting Qt::FastTransformation with Qt::KeepAspectRatio?

          M 1 Reply Last reply
          0
          • B Bonnie

            @Mwoua :

            Is Qt::SmoothTransformation the only alternative?

            For transformMode, yes.
            Aren't you expecting Qt::FastTransformation with Qt::KeepAspectRatio?

            M Offline
            M Offline
            Mwoua
            wrote on last edited by
            #13

            @Bonnie said in Pixel stretched when zooming QImage a lot:

            Qt::KeepAspectRatio

            Well, I want my image to take the entire widget. I dont mind if the pixel are a bit stretched, as long as they all have the same size

            Christian EhrlicherC B 2 Replies Last reply
            0
            • M Mwoua

              @Bonnie said in Pixel stretched when zooming QImage a lot:

              Qt::KeepAspectRatio

              Well, I want my image to take the entire widget. I dont mind if the pixel are a bit stretched, as long as they all have the same size

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #14

              @Mwoua said in Pixel stretched when zooming QImage a lot:

              Well, I want my image to take the entire widget. I dont mind if the pixel are a bit stretched, as long as they all have the same size

              Qt has no such an option. You have to write this scaling method by yourself.

              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
              0
              • M Mwoua has marked this topic as solved on
              • M Mwoua

                @Bonnie said in Pixel stretched when zooming QImage a lot:

                Qt::KeepAspectRatio

                Well, I want my image to take the entire widget. I dont mind if the pixel are a bit stretched, as long as they all have the same size

                B Offline
                B Offline
                Bonnie
                wrote on last edited by Bonnie
                #15

                @Mwoua Hey, I have an idea.
                First use Qt::KeepAspectRatio + Qt::FastTransformation to scale to a ratio-fixed size, then scale it again with Qt::IgnoreAspectRatio + Qt::SmoothTransformation , something like

                QSize targetSize ( width(), height() );
                QImage targetImage = lImage.scaled(targetSize , Qt::KeepAspectRatio, Qt::FastTransformation );
                if(targetImage.size() != targetSize )
                    targetImage = targetImage.scaled(targetSize , Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
                
                M 1 Reply Last reply
                0
                • B Bonnie

                  @Mwoua Hey, I have an idea.
                  First use Qt::KeepAspectRatio + Qt::FastTransformation to scale to a ratio-fixed size, then scale it again with Qt::IgnoreAspectRatio + Qt::SmoothTransformation , something like

                  QSize targetSize ( width(), height() );
                  QImage targetImage = lImage.scaled(targetSize , Qt::KeepAspectRatio, Qt::FastTransformation );
                  if(targetImage.size() != targetSize )
                      targetImage = targetImage.scaled(targetSize , Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
                  
                  M Offline
                  M Offline
                  Mwoua
                  wrote on last edited by
                  #16

                  @Bonnie The first QImage targetImage = lImage.scaled(targetSize , Qt::KeepAspectRatio, Qt::FastTransformation ); is the one that stretch some pixels, but not all. It wont work

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SimonSchroeder
                    wrote on last edited by
                    #17

                    If you double the image in size (i.e. twice the number of pixels in both width and height) it is quite easy to draw the zoomed image by doubling the pixels both in the x and y direction. However, if you don't have a perfect multiple there is no perfect solution available. With the approach that fast transformation uses only some pixels can be doubled. Smooth transformation instead interpolates the colors of neighboring pixels to get a new color. This will always make the image look a little bit blurry. I don't know of any other way than to either use the color of just a single pixel or interpolate the colors of neighboring pixels. Only AI could invent some new pixels to fill the gaps properly (with no guarantee of accuracy of the final image to be displayed). You cannot use information which is not there.

                    The best thing you could do is to scale the image only by multiples of the original size using the fast transformation. A slight variation could be that 50% and 25% of the image size is also easy to achieve. Those images (after first scaling them down) could also be scaled up to multiples of their size with proper pixel sizes. This would allow intermediate steps of 3/2 (3x 50%) or 5/4 (5x 25%). Though, first scaling them down looses some information, but might look good.

                    M 1 Reply Last reply
                    0
                    • S SimonSchroeder

                      If you double the image in size (i.e. twice the number of pixels in both width and height) it is quite easy to draw the zoomed image by doubling the pixels both in the x and y direction. However, if you don't have a perfect multiple there is no perfect solution available. With the approach that fast transformation uses only some pixels can be doubled. Smooth transformation instead interpolates the colors of neighboring pixels to get a new color. This will always make the image look a little bit blurry. I don't know of any other way than to either use the color of just a single pixel or interpolate the colors of neighboring pixels. Only AI could invent some new pixels to fill the gaps properly (with no guarantee of accuracy of the final image to be displayed). You cannot use information which is not there.

                      The best thing you could do is to scale the image only by multiples of the original size using the fast transformation. A slight variation could be that 50% and 25% of the image size is also easy to achieve. Those images (after first scaling them down) could also be scaled up to multiples of their size with proper pixel sizes. This would allow intermediate steps of 3/2 (3x 50%) or 5/4 (5x 25%). Though, first scaling them down looses some information, but might look good.

                      M Offline
                      M Offline
                      Mwoua
                      wrote on last edited by
                      #18

                      @SimonSchroeder Yeah I went with a custom scaling method and using fast transformation.

                      When there are a lot of pixel drawn, I still have some doubled pixel (probably), but i cant notice it because its too small. However, when it is zoomed enough, it looks good.

                      My method is really simple, but it's fast enough. To keep it simple, I compute the area I want to see and copy these pixels to a new buffer I give to QImage. Then I let FastTransformation do its job

                      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