From ec422648ade17bafa234ba1130be1b063bb93de7 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Fri, 22 Oct 2021 09:30:59 +0200 Subject: [PATCH] Examples: Fix image scaling for Qt 6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For Qt 6 we must manually convert images to a larger image space before rescaling, otherwise we get dithering effects. Fixes: QTCREATORBUG-26462 Task-number: QTCREATORBUG-24098 Change-Id: I0d7bb70003822d61d6bc4bc571d29ef82c4dbb0e Reviewed-by: Robert Löhning --- src/plugins/qtsupport/screenshotcropper.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/plugins/qtsupport/screenshotcropper.cpp b/src/plugins/qtsupport/screenshotcropper.cpp index 4595e411434..4997be926f0 100644 --- a/src/plugins/qtsupport/screenshotcropper.cpp +++ b/src/plugins/qtsupport/screenshotcropper.cpp @@ -82,17 +82,20 @@ QImage ScreenshotCropper::croppedImage(const QImage &sourceImage, const QString { const QRect areaOfInterest = welcomeScreenAreas()->areas.value(fileNameForPath(filePath)); + QImage result; if (areaOfInterest.isValid()) { const QRect cropRect = cropRectForAreaOfInterest(sourceImage.size(), cropSize, areaOfInterest); const QSize cropRectSize = cropRect.size(); - const QImage result = sourceImage.copy(cropRect); - if (cropRectSize.width() > cropSize.width() || cropRectSize.height() > cropSize.height()) - return result.scaled(cropSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); - else + result = sourceImage.copy(cropRect); + if (cropRectSize.width() <= cropSize.width() && cropRectSize.height() <= cropSize.height()) return result; + } else { + result = sourceImage; } - return sourceImage.scaled(cropSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); + if (result.format() != QImage::Format_ARGB32) + result = result.convertToFormat(QImage::Format_ARGB32); + return result.scaled(cropSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); } static int areaAttribute(const QXmlStreamAttributes &attributes, const QString &name)