From 153090637bc2e492c435dd484c2e1672832b6362 Mon Sep 17 00:00:00 2001 From: zhuzichu Date: Fri, 18 Aug 2023 12:45:16 +0800 Subject: [PATCH] update --- example/qml/page/T_Screenshot.qml | 1 + src/Screenshot.cpp | 22 ++++++++-------------- src/Screenshot.h | 1 - 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/example/qml/page/T_Screenshot.qml b/example/qml/page/T_Screenshot.qml index f25fb004..197c3e70 100644 --- a/example/qml/page/T_Screenshot.qml +++ b/example/qml/page/T_Screenshot.qml @@ -32,6 +32,7 @@ FluScrollablePage{ Layout.preferredHeight: 400 Layout.preferredWidth: 400 fillMode: Image.PreserveAspectFit + asynchronous: true } FluScreenshot{ diff --git a/src/Screenshot.cpp b/src/Screenshot.cpp index ca7f05bb..cc67105b 100644 --- a/src/Screenshot.cpp +++ b/src/Screenshot.cpp @@ -5,6 +5,7 @@ #include #include #include +#include Screenshot::Screenshot(QQuickItem* parent) : QQuickPaintedItem(parent) { @@ -44,24 +45,18 @@ ScreenshotBackground::ScreenshotBackground(QQuickItem* parent) : QQuickPaintedIt void ScreenshotBackground::paint(QPainter* painter) { painter->save(); - _sourcePixmap = QPixmap(QSize(_desktopPixmap.width(),_desktopPixmap.height())); - QPainter p(&_sourcePixmap); - p.drawPixmap(_desktopGeometry,_desktopPixmap); - painter->drawPixmap(_desktopGeometry,_desktopPixmap); + _sourcePixmap = _desktopPixmap.copy(); + painter->drawPixmap(_desktopGeometry,_sourcePixmap); painter->restore(); } void ScreenshotBackground::capture(const QPoint& start,const QPoint& end){ - _grabResult = grabToImage(); - auto x = qMin(start.x(),end.x()); - auto y = qMin(start.y(),end.y()); - auto w = qAbs(end.x()-start.x()); - auto h = qAbs(end.y()-start.y()); + auto pixelRatio = qApp->primaryScreen()->devicePixelRatio(); + auto x = qMin(start.x(),end.x()) * pixelRatio; + auto y = qMin(start.y(),end.y()) * pixelRatio; + auto w = qAbs(end.x()-start.x()) * pixelRatio; + auto h = qAbs(end.y()-start.y()) * pixelRatio; _captureRect = QRect(x,y,w,h); - connect(_grabResult.data(), &QQuickItemGrabResult::ready, this, &ScreenshotBackground::handleGrabResult); -} - -void ScreenshotBackground::handleGrabResult(){ if(_captureMode == FluScreenshotType::CaptrueMode::Pixmap){ Q_EMIT captrueToPixmapCompleted(_sourcePixmap.copy(_captureRect)); } @@ -71,7 +66,6 @@ void ScreenshotBackground::handleGrabResult(){ dir.mkpath(_saveFolder); } auto filePath = _saveFolder.append("/").append(QString::number(QDateTime::currentDateTime().toMSecsSinceEpoch())).append(".png"); - qDebug()<