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. Antialiasing for QPixmap scaled in a QGraphicsScene
Forum Updated to NodeBB v4.3 + New Features

Antialiasing for QPixmap scaled in a QGraphicsScene

Scheduled Pinned Locked Moved General and Desktop
22 Posts 8 Posters 27.1k 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.
  • J Offline
    J Offline
    JulienMaille
    wrote on last edited by
    #6

    Hey, did you register just to answer me? Thanks a lot!
    Calling setTransformationMode(Qt::SmoothTransformation); on the QGraphicsPixmapItem worked. Now the pixmap is blurred when I zoom in.
    But I still have a strong moiré effect when I zoom out.

    I tried to set this on the QGraphicsView, but it does not help:
    @ setRenderHint(QPainter::HighQualityAntialiasing, true);
    setRenderHint(QPainter::SmoothPixmapTransform, true);@

    1 Reply Last reply
    0
    • L Offline
      L Offline
      loading...
      wrote on last edited by
      #7

      wow, i'm a newbie and i have the same question now.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        blackpainter
        wrote on last edited by
        #8

        I am having exactly the same problem. Here is a short summary what my problem is and what i've tried so far:

        I have a Qgraphicsview with qgraphicspixmapitems in it. Now if i scale the view (zoom out), i get those ugly moire effects:

        !http://i.imgur.com/Eu0S7a2.jpg(Moire effect)!

        what i want though is this, scaled in photoshop:

        !http://i.imgur.com/mwRiq03.jpg(no moire)!

        I tried subclassing qgraphicspixmapitem and set the render hints:
        @void xGraphicsPreviewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
        painter->setRenderHint( QPainter::Antialiasing, true);
        painter->setRenderHint( QPainter::HighQualityAntialiasing, true);
        QGraphicsPixmapItem::paint(painter, option, widget);
        }@

        and also this:
        @void xGraphicsPreviewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
        painter->setRenderHint( QPainter::Antialiasing, true);
        painter->setRenderHint( QPainter::HighQualityAntialiasing, true);
        painter->drawPixmap(boundingRect().topLeft(), this->pixmap());
        }@

        But with both the renderhints do not have any effect on the images. Any help/advice?

        Thanks and Regards

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jassie
          wrote on last edited by
          #9

          Hey, Have you solved this problem? Could you please tell me how?Thank you !

          1 Reply Last reply
          0
          • J Offline
            J Offline
            Jassie
            wrote on last edited by
            #10

            Hey, Have you solved this problem? Could you please tell me how?Thank you !

            1 Reply Last reply
            0
            • B Offline
              B Offline
              blackpainter
              wrote on last edited by
              #11

              Hi Jassie,

              I had to implement it completely manually.
              Simply create small resized versions of your image when loading it or on demand and load them into your graphicsview depending on the zoom value.

              You get the best results when your image has the actual size in which it is displayed in. (e.g. if you zoom out so your image will only be 512px wide, resize it to 512px before loading it into the interface)

              1 Reply Last reply
              0
              • B Offline
                B Offline
                blackpainter
                wrote on last edited by
                #12

                Hi Jassie,

                I had to implement it completely manually.
                Simply create small resized versions of your image when loading it or on demand and load them into your graphicsview depending on the zoom value.

                You get the best results when your image has the actual size in which it is displayed in. (e.g. if you zoom out so your image will only be 512px wide, resize it to 512px before loading it into the interface)

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  Jassie
                  wrote on last edited by
                  #13

                  Hi,

                  Do you mean I should zoom out my image first before I scale the view?

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    Jassie
                    wrote on last edited by
                    #14

                    Hi,

                    Do you mean I should zoom out my image first before I scale the view?

                    1 Reply Last reply
                    0
                    • B Offline
                      B Offline
                      blackpainter
                      wrote on last edited by
                      #15

                      As an example:
                      I load my original image with size 1024px. It is displayed in my graphicsview with the same size.
                      Now i zoom out 50%. But instead of scaling the graphicsview, simply resize the original image to 512px (with QT or openCV) and reload it into the graphicsview.

                      1 Reply Last reply
                      0
                      • B Offline
                        B Offline
                        blackpainter
                        wrote on last edited by
                        #16

                        As an example:
                        I load my original image with size 1024px. It is displayed in my graphicsview with the same size.
                        Now i zoom out 50%. But instead of scaling the graphicsview, simply resize the original image to 512px (with QT or openCV) and reload it into the graphicsview.

                        1 Reply Last reply
                        0
                        • J Offline
                          J Offline
                          Jassie
                          wrote on last edited by
                          #17

                          Thank you.But If I scale the image manually everytime I scale the view in wheelevent,it costs so much time. Is there any better way to solve this problem?

                          1 Reply Last reply
                          0
                          • J Offline
                            J Offline
                            Jassie
                            wrote on last edited by
                            #18

                            Thank you.But If I scale the image manually everytime I scale the view in wheelevent,it costs so much time. Is there any better way to solve this problem?

                            1 Reply Last reply
                            0
                            • E Offline
                              E Offline
                              euchkatzl
                              wrote on last edited by
                              #19

                              When you want the best result there is no other option as drawing the image in exact the size shown on screen.(in Pixel)

                              To archive this you could subclass QGraphicsPixmapItem and override paint.

                              There you have to load the pixmap in the correct size (try to map your scene coordinates to pixels).

                              To load an Image in an scaled size you could for example use QImageReader :

                              http://doc.qt.io/qt-5/qimagereader.html#setScaledSize

                              Of course you have to cache the loaded Pixmap yourself.
                              When you reach paint event with the same size your code should use the cached pixmap.

                              1 Reply Last reply
                              0
                              • E Offline
                                E Offline
                                euchkatzl
                                wrote on last edited by
                                #20

                                When you want the best result there is no other option as drawing the image in exact the size shown on screen.(in Pixel)

                                To archive this you could subclass QGraphicsPixmapItem and override paint.

                                There you have to load the pixmap in the correct size (try to map your scene coordinates to pixels).

                                To load an Image in an scaled size you could for example use QImageReader :

                                http://doc.qt.io/qt-5/qimagereader.html#setScaledSize

                                Of course you have to cache the loaded Pixmap yourself.
                                When you reach paint event with the same size your code should use the cached pixmap.

                                1 Reply Last reply
                                0
                                • B Offline
                                  B Offline
                                  blackpainter
                                  wrote on last edited by
                                  #21

                                  Or simply calculate all possible images for all zoom steps at the start.

                                  That means if your zoom values range from 10% to 100% with zoom step +10% simply calculate all 9 images at the start, cache them and load them depending on the zoom value.

                                  QPixmap pixmap100, pixmap90, pixmap80, pixmap70 ... (etc)

                                  you would have to limit the number of possible zoom values of course to avoid long loading times and huge amount of data.

                                  1 Reply Last reply
                                  0
                                  • B Offline
                                    B Offline
                                    blackpainter
                                    wrote on last edited by
                                    #22

                                    Or simply calculate all possible images for all zoom steps at the start.

                                    That means if your zoom values range from 10% to 100% with zoom step +10% simply calculate all 9 images at the start, cache them and load them depending on the zoom value.

                                    QPixmap pixmap100, pixmap90, pixmap80, pixmap70 ... (etc)

                                    you would have to limit the number of possible zoom values of course to avoid long loading times and huge amount of data.

                                    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