GrabToImage on scaled desktop for Windows
-
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)
-
Hi David,
Please show the relevant code snipped (using the code formatting tags) and explain, in which way the result is wrong. -
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
-
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); }
-
Sorry public git interface is:
git clone https://dboosalis@bitbucket.org/boosalis/getimage.git -
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. -
Hi Axel, very sorry about that.
The saved Image with Display Settings at 100% is this:
The saved Image when my Windows Desktop is set to 150% is this:
But in both case the region I want to capture (red box above) is correct for both displays
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); }) }
-
-
Thanks for sharing! It’s actually a bug, which the workaround clearly demonstrates.