Skip to content

Commit 9cb225e

Browse files
authored
Fix result images being rescaled on HDPI monitors (#342)
Merged
1 parent e7f0f7d commit 9cb225e

File tree

3 files changed

+6
-12
lines changed

3 files changed

+6
-12
lines changed

src/annotations/core/AnnotationArea.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,13 @@ QImage AnnotationArea::image()
107107
mItemModifier->clear();
108108

109109
setSceneRect(canvasRect());
110-
auto scaleFactor = mDevicePixelRatioScaler->scaleFactor();
111-
auto sceneRect = this->sceneRect();
112-
auto scaledSceneSize = sceneRect.size().toSize() * scaleFactor;
113-
auto scaledSceneRect = QRectF(sceneRect.topLeft(), scaledSceneSize);
114-
QImage image(scaledSceneSize, QImage::Format_ARGB32_Premultiplied);
110+
auto sceneRect = this->sceneRect().toRect();
111+
QImage image(sceneRect.size(), QImage::Format_ARGB32_Premultiplied);
115112
image.fill(mCanvasColor);
116-
image.setDevicePixelRatio(scaleFactor);
117113

118114
QPainter painter(&image);
119115
painter.setRenderHint(QPainter::Antialiasing);
120-
render(&painter, QRectF(), scaledSceneRect);
116+
render(&painter, QRectF(), sceneRect);
121117

122118
setSceneRect(QRect()); // Reset scene rect
123119

tests/annotations/core/AnnotationAreaTest.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void AnnotationAreaTest::ExportAsImage_Should_ExportEmptyImage_When_NoImageSet()
4747
QCOMPARE(QImage(), resultImage);
4848
}
4949

50-
void AnnotationAreaTest::ExportAsImage_Should_ExportScaledImage_When_ScalingEnabled()
50+
void AnnotationAreaTest::ExportAsImage_Should_ExportUnscaledImage_When_ScalingEnabled()
5151
{
5252
auto scaleFactor = 1.5;
5353
QPixmap pixmap(QSize(400, 400));
@@ -61,9 +61,7 @@ void AnnotationAreaTest::ExportAsImage_Should_ExportScaledImage_When_ScalingEnab
6161

6262
auto resultImage = annotationArea.image();
6363

64-
auto expectedImage = pixmap.scaled(pixmap.size() * scaleFactor).toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied);
65-
expectedImage.setDevicePixelRatio(scaleFactor);
66-
QCOMPARE(resultImage, expectedImage);
64+
QCOMPARE(resultImage, pixmap.toImage());
6765
}
6866

6967
void AnnotationAreaTest::AddAnnotationItem_Should_AddAnnotationItemToScene()

tests/annotations/core/AnnotationAreaTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Q_OBJECT
4242
private slots:
4343
void ExportAsImage_Should_ExportImage_When_ImageSet();
4444
void ExportAsImage_Should_ExportEmptyImage_When_NoImageSet();
45-
void ExportAsImage_Should_ExportScaledImage_When_ScalingEnabled();
45+
void ExportAsImage_Should_ExportUnscaledImage_When_ScalingEnabled();
4646
void AddAnnotationItem_Should_AddAnnotationItemToScene();
4747
void RemoveAnnotationItem_Should_RemoveAnnotationItemFromScene();
4848
void CanvasRect_Should_ReturnRectUnionOfAllItems_When_NoCanvasRectSet();

0 commit comments

Comments
 (0)