Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions src/annotations/core/AnnotationArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,13 @@ QImage AnnotationArea::image()
mItemModifier->clear();

setSceneRect(canvasRect());
auto scaleFactor = mDevicePixelRatioScaler->scaleFactor();
auto sceneRect = this->sceneRect();
auto scaledSceneSize = sceneRect.size().toSize() * scaleFactor;
auto scaledSceneRect = QRectF(sceneRect.topLeft(), scaledSceneSize);
QImage image(scaledSceneSize, QImage::Format_ARGB32_Premultiplied);
auto sceneRect = this->sceneRect().toRect();
QImage image(sceneRect.size(), QImage::Format_ARGB32_Premultiplied);
image.fill(mCanvasColor);
image.setDevicePixelRatio(scaleFactor);

QPainter painter(&image);
painter.setRenderHint(QPainter::Antialiasing);
render(&painter, QRectF(), scaledSceneRect);
render(&painter, QRectF(), sceneRect);

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

Expand Down
6 changes: 2 additions & 4 deletions tests/annotations/core/AnnotationAreaTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void AnnotationAreaTest::ExportAsImage_Should_ExportEmptyImage_When_NoImageSet()
QCOMPARE(QImage(), resultImage);
}

void AnnotationAreaTest::ExportAsImage_Should_ExportScaledImage_When_ScalingEnabled()
void AnnotationAreaTest::ExportAsImage_Should_ExportUnscaledImage_When_ScalingEnabled()
{
auto scaleFactor = 1.5;
QPixmap pixmap(QSize(400, 400));
Expand All @@ -61,9 +61,7 @@ void AnnotationAreaTest::ExportAsImage_Should_ExportScaledImage_When_ScalingEnab

auto resultImage = annotationArea.image();

auto expectedImage = pixmap.scaled(pixmap.size() * scaleFactor).toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied);
expectedImage.setDevicePixelRatio(scaleFactor);
QCOMPARE(resultImage, expectedImage);
QCOMPARE(resultImage, pixmap.toImage());
}

void AnnotationAreaTest::AddAnnotationItem_Should_AddAnnotationItemToScene()
Expand Down
2 changes: 1 addition & 1 deletion tests/annotations/core/AnnotationAreaTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Q_OBJECT
private slots:
void ExportAsImage_Should_ExportImage_When_ImageSet();
void ExportAsImage_Should_ExportEmptyImage_When_NoImageSet();
void ExportAsImage_Should_ExportScaledImage_When_ScalingEnabled();
void ExportAsImage_Should_ExportUnscaledImage_When_ScalingEnabled();
void AddAnnotationItem_Should_AddAnnotationItemToScene();
void RemoveAnnotationItem_Should_RemoveAnnotationItemFromScene();
void CanvasRect_Should_ReturnRectUnionOfAllItems_When_NoCanvasRectSet();
Expand Down