Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. GrabToImage on scaled desktop for Windows
Forum Updated to NodeBB v4.3 + New Features

GrabToImage on scaled desktop for Windows

Scheduled Pinned Locked Moved Solved QML and Qt Quick
10 Posts 2 Posters 841 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.
  • D Offline
    D Offline
    David Boo
    wrote on last edited by David Boo
    #1

    GrabToImage works fine on a monitor that has the Display factor size set to 100%, but when I try it on a monitor with the Display factor size set to 150% (which is recommended by Windows) the results of grabToImage are wrong.

    Is this a bug ? Is it something I am doing wrong ? Are there any work arounds other then to tell the use to using only 100% for Display scale size.

    Thanks in advance for any help.

    -David

    (I am using Qt 6.7.1 with MSVC 2019 on Windows 11)

    1 Reply Last reply
    0
    • Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote on last edited by
      #2

      Hi David,
      Please show the relevant code snipped (using the code formatting tags) and explain, in which way the result is wrong.

      Software Engineer
      The Qt Company, Oslo

      1 Reply Last reply
      0
      • D Offline
        D Offline
        David Boo
        wrote on last edited by
        #3

        Sorry for the delay. I was on vacation :) and thank for responding. I created a small git repository that is open, It is a tiny example and can be found here:

        git clone git@bitbucket.org:boosalis/getimage.git

        1 Reply Last reply
        0
        • D Offline
          D Offline
          David Boo
          wrote on last edited by David Boo
          #4
           Button {
                  id: saveToFileB
                  text: "Save Image"
                  anchors.top: parent.top
                  anchors.horizontalCenter: parent.horizontalCenter
                  onPressed:  {
                      // yes I know selection area x & y area little offset but
                      imageArea.grabToImage(function(result) {
                          controller.saveImage(select.x, select.y, select.width, select.height,result.image)
          
                      })
                  }
              }
              Item {
                  id: workArea
                  anchors.top: saveToFileB.bottom
                  anchors.left: parent.left
                  anchors.right: parent.right
                  anchors.bottom: instructionsL.top
                  Image {
                      id: imageArea
                      source: "qrc:/DDOG.svg"
                      anchors.fill: parent
                  }
                  Rectangle {
                      id: select
                      anchors.centerIn: imageArea
                      width: 200
                      height:200
                      color: "transparent"
                      border.width: 2
                      border.color: "red"
                      z: 2
                  }
              }
          
          Q_INVOKABLE void saveImage(int x, int y, int w, int h ,QVariant img) {
                  QString tempFileName = QDir::homePath() + "/grabImage.tiff";
                  QImage wholeImage = img.value<QImage>();
                  QImage selectionOfImage = wholeImage.copy(x,y,w,h);
                  selectionOfImage.save(tempFileName);
              }
          
          
          1 Reply Last reply
          0
          • D Offline
            D Offline
            David Boo
            wrote on last edited by
            #5

            screenGrabApp.png

            1 Reply Last reply
            0
            • D Offline
              D Offline
              David Boo
              wrote on last edited by
              #6

              Sorry public git interface is:
              git clone https://dboosalis@bitbucket.org/boosalis/getimage.git

              1 Reply Last reply
              0
              • Axel SpoerlA Offline
                Axel SpoerlA Offline
                Axel Spoerl
                Moderators
                wrote on last edited by
                #7

                Hi David,
                You have answered the first of my question by posting the relevant code. You still haven’t explained, why you believe the result is wrong. Please don’t post external links. The bitbucket link is broken anyway. Just paste the photo here like you did with the screenshot.

                Software Engineer
                The Qt Company, Oslo

                1 Reply Last reply
                1
                • D Offline
                  D Offline
                  David Boo
                  wrote on last edited by
                  #8

                  Hi Axel, very sorry about that.

                  The saved Image with Display Settings at 100% is this:
                  grabImageNormalScale.png

                  The saved Image when my Windows Desktop is set to 150% is this:
                  grabImage150Scale.png

                  But in both case the region I want to capture (red box above) is correct for both displays

                  D 1 Reply Last reply
                  0
                  • D David Boo

                    Hi Axel, very sorry about that.

                    The saved Image with Display Settings at 100% is this:
                    grabImageNormalScale.png

                    The saved Image when my Windows Desktop is set to 150% is this:
                    grabImage150Scale.png

                    But in both case the region I want to capture (red box above) is correct for both displays

                    D Offline
                    D Offline
                    David Boo
                    wrote on last edited by
                    #9

                    @David-Boo

                    I resolved the issue with this:

                    function testShot() {
                            pdfViewer.grabToImage(function(result) {
                                let pd = Screen.devicePixelRatio
                                controller.getSelection(selector.x*pd, selector.y*pd,selector.width*pd,selector.height*pd,result.image);
                            })
                        }
                    
                    1 Reply Last reply
                    1
                    • D David Boo has marked this topic as solved on
                    • Axel SpoerlA Offline
                      Axel SpoerlA Offline
                      Axel Spoerl
                      Moderators
                      wrote on last edited by
                      #10

                      Thanks for sharing! It’s actually a bug, which the workaround clearly demonstrates.

                      Software Engineer
                      The Qt Company, Oslo

                      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