Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mac] Copying an image makes it blurry #1649

Open
csa-smt opened this issue Dec 12, 2024 · 0 comments
Open

[Mac] Copying an image makes it blurry #1649

csa-smt opened this issue Dec 12, 2024 · 0 comments

Comments

@csa-smt
Copy link

csa-smt commented Dec 12, 2024

Describe the bug
On MacOS, when using the constructor org.eclipse.swt.graphics.Image#Image(org.eclipse.swt.graphics.Device, org.eclipse.swt.graphics.Image, int), the new image is more blurry, and the base image too.
The base image and its copies become more and more blurry as we use the same constructor again.
The bug seems to be created when the base image was created from an ImageDescriptor.
The bug occurs with any flag passed as a parameter to create the new image.

To Reproduce

Edit IMAGE_PATH to put the path to your icon, by example you can download it: file_icon

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import java.io.File;
import java.net.MalformedURLException;

public final class HelloWorld {

    private static final String IMAGE_PATH = "/path/to/file_icon.png";

    public static void main(final String[] args) throws MalformedURLException {
        final Display display = new Display();
        final Shell shell = new Shell(display);


        final ImageDescriptor imageDescriptor = ImageDescriptor.createFromURL(new File(IMAGE_PATH).toURI().toURL());
        final Image baseImage = imageDescriptor.createImage();
        final int imageWidth = baseImage.getImageData().width;

        shell.addListener(SWT.Paint, event -> {
            int x = 0;
            for (int i = 0; i < 10; i++) {
                final Image copy = new Image(baseImage.getDevice(), baseImage, SWT.IMAGE_COPY);
                event.gc.drawImage(copy, x, 0);
                x += imageWidth + 10;
                event.gc.drawImage(baseImage, x, 0);
                x += imageWidth + 10;
                copy.dispose();
            }
        });

        shell.setSize(400, 300);
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
        baseImage.dispose();
        display.dispose();
    }
}

Expected behavior
The base image and its copies must not be blurry.

Screenshots
screenshot

Environment:

  1. Select the platform(s) on which the behavior is seen:
    • All OS
    • Windows
    • Linux
    • macOS
  1. Additional OS info

Tried on : MacOS Sequoia, aarch64

  1. JRE/JDK version

Tried on Eclipse Temurin 21.0.5

Workaround

Create a temporary image by passing the ImageData of the base image.

Replace...

final Image copy = new Image(baseImage.getDevice(), baseImage, SWT.IMAGE_COPY);

... with

final Image tmpImage = new Image(baseImage.getDevice(), baseImage.getImageData());
final Image copy = new Image(baseImage.getDevice(), tmpImage, SWT.IMAGE_COPY);
tmpImage.dispose();
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

No branches or pull requests

1 participant