Examples: Fix image scaling for Qt 6

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 <robert.loehning@qt.io>
This commit is contained in:
Eike Ziller
2021-10-22 09:30:59 +02:00
parent f4db436a7b
commit ec422648ad

View File

@@ -82,17 +82,20 @@ QImage ScreenshotCropper::croppedImage(const QImage &sourceImage, const QString
{ {
const QRect areaOfInterest = welcomeScreenAreas()->areas.value(fileNameForPath(filePath)); const QRect areaOfInterest = welcomeScreenAreas()->areas.value(fileNameForPath(filePath));
QImage result;
if (areaOfInterest.isValid()) { if (areaOfInterest.isValid()) {
const QRect cropRect = cropRectForAreaOfInterest(sourceImage.size(), cropSize, areaOfInterest); const QRect cropRect = cropRectForAreaOfInterest(sourceImage.size(), cropSize, areaOfInterest);
const QSize cropRectSize = cropRect.size(); const QSize cropRectSize = cropRect.size();
const QImage result = sourceImage.copy(cropRect); result = sourceImage.copy(cropRect);
if (cropRectSize.width() > cropSize.width() || cropRectSize.height() > cropSize.height()) if (cropRectSize.width() <= cropSize.width() && cropRectSize.height() <= cropSize.height())
return result.scaled(cropSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
else
return result; 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) static int areaAttribute(const QXmlStreamAttributes &attributes, const QString &name)