In windows explorer (and linux gnome) shows for each file a thumbnail or icon. Like with EXEs, images, videos, txt-files, ini-files, Word documents and so much other file types. Now is my question: Is there a way to get a (preferably large) icon by file.
Something like:
public static BufferedImage getThumbnail(File file) {...}
Thanks
It looks like there is no AWT way of doing this.
If you're using Swing, there is a method you can use to get a Swing Icon
...
import javax.swing.filechooser.FileSystemView;
import javax.swing.Icon;
...
Icon ico = FileSystemView.getFileSystemView().getSystemIcon(file);
You can also convert that Icon
back into an Image
(most likely a BufferedImage, but I haven't tested it):
Image image = ((ImageIcon) ico).getImage();
There is also a class to get the icon directly, but this class is JDK dependent. On Sun JDK's it's the sun.awt.shell.ShellFolder
class.
If you're using SWT, things are a bit trickier.
I don't think the answers above are addressing the right question. Martijn isn't asking for the API for manipulating icon images. He wants to know how to get to the desktop's cache of thumbnail images for items in the browsable filesystem.
I don't think there's a portable way to do this at all, but the Linux world (Gnome and KDE) adhere to the Freedesktop thumbnail standard which can be read at: http://jens.triq.net/thumbnail-spec/
There may be code, perhaps in Gtk (but probably not Java) that implements a compatibility layer for windows, but I'm not aware of it if there is.
If you are looking for a plattform-independent (i.e. pure java) solution, hava a look at JavaThumbnailer. It's still beta, though, and has a limited number of supported file types.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With