Java icon class to image

edited May 2016 in How To...

Hello,

I am looking to display the image of an icon of a file (Java File class used and then Icon class to get image: Icon ico = FileSystemView.getFileSystemView().getSystemIcon(file);)...

Does anyone have any ideas on how to render/display this icon image in Processing?

Answers

  • Or maybe a conversion to PImage....?

  • edited March 2014 Answer ✓

    Wrote you a little wrapper function that converts Icon to PImage:

    import javax.swing.filechooser.FileSystemView;
    import javax.swing.ImageIcon;
    import java.awt.Image;
    
    void setup() {
        PImage iconImage = getIcon("C:\\Users\\Poersch\\Desktop\\some-file-on-my-desktop.txt");
        image(iconImage, 0, 0);
    }
    
    PImage getIcon(String filename) {
        ImageIcon imageIcon = (ImageIcon)FileSystemView.getFileSystemView().getSystemIcon(new File(filename));
        return new PImage(imageIcon.getImage());
    }
    
  • Thank you very much!

Sign In or Register to comment.