Skip to content

[Windows Hi-DPI] Program icons have black background #715

Closed

Description

@Phillipus

Windows 10/11
Eclipse 4.28
Windows hi-dpi scaling at 200%.

Some program icons in Package Explorer and Project Explorer have a black background:

explorer

Sometimes, the icons render correctly.

I can't reproduce this with a stand-alone SWT snippet so it seems to suggest that it's caused by Eclipse doing things in a certain order, or something else affects it in the UI.

See also #185

Activity

  1. deepika-u commented on Jun 30, 2023

    @deepika-u
    Contributor

    Hi @Phillipus,
    For me this looks to be similar issue reported in pr #409. Can you please review that issue if that might give you some clue towards this problem.
    Thanks

  2. Phillipus commented on Jun 30, 2023

    @Phillipus
    ContributorAuthor

    Hi @Phillipus, For me this looks to be similar issue reported in pr #409. Can you please review that issue if that might give you some clue towards this problem. Thanks

    Hi @deepika-u I tested running a child Eclipse with the SWT PR (and the PR in Platform UI) but, unfortunately, the program icons still have a black background.

    I think it's related to #185

  3. Phillipus commented on Jun 30, 2023

    @Phillipus
    ContributorAuthor

    I think it's related to #185

    Actually, it's not a recent regression. The problem exists in Eclipse 4.8 (June 2018)

  4. merks commented on Jun 30, 2023

    @merks
    Contributor

    Yes, this is quite an old problem. BTW, I think these come from org.eclipse.swt.program.Program.getPrograms() and from there via org.eclipse.swt.program.Program.getImageData() which works it's way tout of org.eclipse.ui.internal.misc.ExternalProgramImageDescriptor.getImageData() eventually. Unfortunately org.eclipse.swt.tests.win32.snippets.SWTIssue185.createImages(Display, String...) does not not reproduce the problem.

  5. Phillipus commented on Jun 30, 2023

    @Phillipus
    ContributorAuthor

    ....does not not reproduce the problem.

    And I can't reproduce it in a stand-alone SWT snippet. And the infuriating thing is (in terms of debugging) is that sometimes the icons render OK!

  6. Phillipus commented on Jul 2, 2023

    @Phillipus
    ContributorAuthor

    In the org.eclipse.swt.program.Program class starting at line 363:

    public ImageData getImageData () {
    	if (extension != null) {
    		SHFILEINFO shfi = new SHFILEINFO ();
    		int flags = OS.SHGFI_ICON | OS.SHGFI_SMALLICON | OS.SHGFI_USEFILEATTRIBUTES;
    ...

    If I change line 366 to one of the following the icon is displayed correctly:

    int flags = OS.SHGFI_SMALLICON | OS.SHGFI_USEFILEATTRIBUTES;
    
    int flags = OS.SHGFI_ICON | OS.SHGFI_SMALLICON;
    
    int flags = OS.SHGFI_SMALLICON;
    

    I've no idea what those flags mean or why this should be the case, but maybe a clue there?

  7. Phillipus commented on Jul 2, 2023

    @Phillipus
    ContributorAuthor

    In fact, if I comment out all of this, it works:

    if (extension != null) {
    	SHFILEINFO shfi = new SHFILEINFO ();
    	int flags = OS.SHGFI_ICON | OS.SHGFI_SMALLICON | OS.SHGFI_USEFILEATTRIBUTES;
    	TCHAR pszPath = new TCHAR (0, extension, true);
    	OS.SHGetFileInfo (pszPath.chars, OS.FILE_ATTRIBUTE_NORMAL, shfi, SHFILEINFO.sizeof, flags);
    	if (shfi.hIcon != 0) {
    		Image image = Image.win32_new (null, SWT.ICON, shfi.hIcon);
    		/* Fetch the ImageData at 100% zoom and return */
    		ImageData imageData = image.getImageData ();
    		image.dispose ();
    		return imageData;
    	}
    }
  8. deepika-u commented on Aug 17, 2023

    @deepika-u
    Contributor

    Hi, I tried the below images in the snippet. Please check if you are able to recreate the problem with this snippet.

    package org.eclipse.swt.bugs;
    import org.eclipse.swt.*;
    import org.eclipse.swt.graphics.*;
    import org.eclipse.swt.layout.*;
    import org.eclipse.swt.widgets.*;
    
    public class SWTIconExample {
    
        public static void main(String[] args) {
            Display display = new Display();
            Shell shell = new Shell(display);
            shell.setText("Excel and Chrome Icons");
            shell.setLayout(new GridLayout(2, false));
    
            // Load the Excel icon
            Image excelIcon = new Image(display, "C:\\Users\\02236C744\\Desktop\\zoom_icons\\ExcelLogoSmall.scale-100.png");
            // Load the Chrome icon
            Image chromeIcon = new Image(display, "C:\\Users\\02236C744\\Desktop\\zoom_icons\\chrome.png");
            // Load the Firefox icon
            Image firefoxIcon = new Image(display, "C:\\Users\\02236C744\\Desktop\\zoom_icons\\VisualElements_70.png");
            // Load the Edge icon
            Image edgeIcon = new Image(display, "C:\\Users\\02236C744\\Desktop\\zoom_icons\\edge.png");
            // Load the MSWord icon
            Image mswordIcon = new Image(display, "C:\\Users\\02236C744\\Desktop\\zoom_icons\\WinWordLogoSmall.scale-100.png");
    
            // Label to display the Excel icon
            Label excelLabel = new Label(shell, SWT.NONE);
            excelLabel.setImage(excelIcon);
            excelLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
    
            // Label to display the Chrome icon
            Label chromeLabel = new Label(shell, SWT.NONE);
            chromeLabel.setImage(chromeIcon);
            chromeLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
    
            // Label to display the Firefox icon
            Label firefoxLabel = new Label(shell, SWT.NONE);
            firefoxLabel.setImage(firefoxIcon);
            firefoxLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
    
            // Label to display the Edge icon
            Label edgeLabel = new Label(shell, SWT.NONE);
            edgeLabel.setImage(edgeIcon);
            edgeLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
    
            // Label to display the MSWord icon
            Label mswordLabel = new Label(shell, SWT.NONE);
            mswordLabel.setImage(mswordIcon);
            mswordLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
    
            shell.pack();
            shell.open();
    
            while (!shell.isDisposed()) {
                if (!display.readAndDispatch()) {
                    display.sleep();
                }
            }
    
            // Remember to dispose of the images
            excelIcon.dispose();
            chromeIcon.dispose();
            firefoxIcon.dispose();
            edgeIcon.dispose();
            mswordIcon.dispose();
            display.dispose();
        }
    }
    

    I have picked the images at that path from below locations already existing in my windows 11 instance.
    firefox => C:\Program Files\Mozilla Firefox\browser\VisualElements
    excel, word => C:\Program Files\Microsoft Office\root\Office16\LogoImages
    chrome, edge => C:\Program Files\Microsoft Office\root\Office16\sdxs\FA000000070\assets\src\assets\images
    edge => C:\Program Files (x86)\Microsoft\Edge\Application\115.0.1901.203\VisualElements

    Let me know if anyone is able to recreate the issue atleast i am not successful.

  9. Phillipus commented on Aug 17, 2023

    @Phillipus
    ContributorAuthor

    @deepika-u I can't reproduce this with a stand-alone snippet. As mentioned before it seems to depend on the order of events.

  10. deepika-u commented on Jan 4, 2024

    @deepika-u
    Contributor

    @Phillipus
    Can you please check below snippet

    package org.eclipse.swt.bugs3;
    import java.util.*;
    import java.util.List;
    
    import org.eclipse.swt.*;
    import org.eclipse.swt.graphics.*;
    import org.eclipse.swt.program.*;
    import org.eclipse.swt.widgets.*;
    
    public class ProgramImageTest {
    
    	public static void main(String[] args) {
    		final Display display = new Display();
    
    		final List<Image> images = createImages(display, "svg", "shtml", "html", "xlsx", "docx", "zip", "pdf", "png", "jpg", "msi", "txt", "theme");
    
    		final Shell shell = new Shell(display);
    
    		shell.addListener(SWT.Paint, event -> {
    			int x = 0;
    			for (Image image : images) {
    				event.gc.drawImage(image, x, 0);
    				x += image.getImageData().width;
    				x += 10;
    			}
    		});
    
    		shell.setSize(400, 300);
    		shell.open();
    
    		while (!shell.isDisposed()) {
    			if (!display.readAndDispatch()) {
    				display.sleep();
    			}
    		}
    
    		for (Image image : images) {
    			image.dispose();
    		}
    
    		display.dispose();
    	}
    
    	private static List<Image> createImages(Display display, String... extensions) {
    		final List<Image> images = new ArrayList<>();
    		for (String extension : extensions) {
    			final Program program = Program.findProgram(extension);
    			if (program == null) {
    				continue;
    			}
    
    			final ImageData data = program.getImageData();
    			if (data == null) {
    				continue;
    			}
    
    			images.add(new Image(display, data));
    		}
    		return images;
    	}
    }
    
    

    Hope this should help you recreate the problem.

  11. Phillipus commented on Jan 4, 2024

    @Phillipus
    ContributorAuthor

    @deepika-u This is the result of the Snippet. It doesn't recreate the problem.

    Image 001

  12. deepika-u commented on Jan 4, 2024

    @deepika-u
    Contributor

    @deepika-u This is the result of the Snippet. It doesn't recreate the problem.

    @Phillipus : have you got to try with 200% resolution? is it the same? sorry to ask you again.

  13. Phillipus commented on Jan 4, 2024

    @Phillipus
    ContributorAuthor

    Yes, that's at 200%.

  14. 32 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions