Skip to content

Conversation

@ptziegler
Copy link
Contributor

@ptziegler ptziegler commented Jul 2, 2025

The current implementation always takes a screenshot of the Swing components at 100% zoom, which is then up-scaled to match the display zoom. Doing so results in blurry and low-quality images.

Instead, the screenshot is taken at the current zoom level and contained in an ImageDataProvider. When the image is painted this then allows us to use the correctly scaled image data. Note that artifical scaling is still done, if a different zoom level is requested.

Closes #506

@ptziegler ptziegler marked this pull request as draft July 2, 2025 21:09
@ptziegler ptziegler force-pushed the issue506 branch 2 times, most recently from a933d47 to f55f1f7 Compare July 4, 2025 21:01
@ptziegler
Copy link
Contributor Author

A partial success: The image is now properly scaled to the display zoom, but the source image created as if at 100% zoom.

image

@ptziegler
Copy link
Contributor Author

ptziegler commented Jul 4, 2025

Hm... If I understand the current implementation correctly, the screenshot is always taken at 100% zoom and then artificially upscaled to the actual display zoom. This leads to very blurry images.

The decorations of the JFrame are a separate issue which I think can only be fixed in the JDK itself. But I would expect the same issue to be at play here.

Furthermore, one little quirk is that getWidth() and getHeight() always returns the width and height at 100% zoom as well. This isn't an issue now as the entire screenshot is taken at 100% zoom but will, when the image is scaled properly.

@ptziegler
Copy link
Contributor Author

Furthermore, one little quirk is that getWidth() and getHeight() always returns the width and height at 100% zoom as well. This isn't an issue now as the entire screenshot is taken at 100% zoom but will, when the image is scaled properly.

I suppose this makes sense. The whole UI is created and drawn by Swing, so there is no issue with drawing everything at 100% and then scaling it to whatever zoom is requested. Funnily enough, the same approach is what Andreas suggested for e.g. GEF, in order to fix some of the rounding errors.

@ptziegler ptziegler force-pushed the issue506 branch 7 times, most recently from d9f6870 to 2e2961e Compare July 5, 2025 10:41
@ptziegler ptziegler added this to the 1.21.0 milestone Jul 5, 2025
@ptziegler ptziegler marked this pull request as ready for review July 5, 2025 10:42
if (EnvironmentUtils.IS_MAC) {
return 1.0;
}
return component.getGraphicsConfiguration().getDefaultTransform().getScaleX();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked long and hard at the changes done in 6d8cdc2 and I think they have aged incredibly poorly. However, without a Mac to test it with, I have no way of checking how good/bad the editor is looking.
Long story short: This keeps the current behavior of taking everything at 100% zoom.

The current implementation always takes a screenshot of the Swing
components at 100% zoom, which is then up-scaled to match the display
zoom. Doing so results in blurry and low-quality images.

Instead, the screenshot is taken at the current zoom level and contained
in an ImageDataProvider. When the image is painted this then allows us
to use the correctly scaled image data. Note that artifical scaling is
still done, if a different zoom level is requested.

Closes eclipse-windowbuilder#506
@ptziegler ptziegler merged commit cca651f into eclipse-windowbuilder:master Jul 8, 2025
8 checks passed
@ptziegler ptziegler deleted the issue506 branch July 8, 2025 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Long refresh time for large Swing screens

1 participant