Qt5,Qt6: fixed distorted image creation from device (screenshoot) on HiDpi screens.

(cherry-picked from commit 291a9fd3dd)

Co-authored-by: zeljan1 <zeljko@holobit.hr>
This commit is contained in:
Željan Rikalo 2025-02-11 08:59:23 +00:00 committed by Željan Rikalo
parent a540e7372b
commit 2754524965
2 changed files with 6 additions and 4 deletions

View File

@ -755,6 +755,7 @@ var
Image: QImageH;
Context: TQtDeviceContext;
AWnd: HWND;
APixelRatio: QReal;
procedure RawImage_FromImage(AImage: QImageH);
begin
@ -788,8 +789,8 @@ begin
if Context.Parent <> nil then
begin
AWnd := HwndFromWidgetH(Context.Parent);
// AWnd should never be 0 at this point
APixmap := TQtWidget(AWnd).grabWindow(0, 0, DCSize.cx, DCSize.cy, Context.Parent);
APixelRatio := QScreen_devicePixelRatio(QWindow_screen(QWidget_windowHandle(Context.Parent)));
APixmap := TQtWidget(AWnd).grabWindow(0, 0, Round(DCSize.cx / APixelRatio), Round(DCSize.cy / APixelRatio), Context.Parent);
Image := QImage_Create;
QPixmap_toImage(APixmap, Image);
RawImage_FromImage(Image);

View File

@ -774,6 +774,7 @@ var
Image: QImageH;
Context: TQtDeviceContext;
AWnd: HWND;
APixelRatio: QReal;
procedure RawImage_FromImage(AImage: QImageH);
begin
@ -807,8 +808,8 @@ begin
if Context.Parent <> nil then
begin
AWnd := HwndFromWidgetH(Context.Parent);
// AWnd should never be 0 at this point
APixmap := TQtWidget(AWnd).grabWindow(0, 0, DCSize.cx, DCSize.cy, Context.Parent);
APixelRatio := QScreen_devicePixelRatio(QWidget_screen(Context.Parent));
APixmap := TQtWidget(AWnd).grabWindow(0, 0, Round(DCSize.cx / APixelRatio), Round(DCSize.cy / APixelRatio), Context.Parent);
Image := QImage_Create;
QPixmap_toImage(APixmap, Image);
RawImage_FromImage(Image);