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

This commit is contained in:
zeljan1 2025-02-11 09:40:54 +01:00
parent 32c1370c50
commit 291a9fd3dd
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);