Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Image getImage(File file) throws FileNotFoundException {
- sun.awt.shell.ShellFolder sf = sun.awt.shell.ShellFolder.getShellFolder(file);
- return new ImageIcon(sf.getIcon(true)).getImage();
- }
- FileSystemView.getFileSystemView().getSystemIcon(file);
- public static void writePNG(File f, BufferedImage img) throws Exception {
- ImageWriter writer = null;
- f.createNewFile();
- try(FileImageOutputStream output = new FileImageOutputStream(f.getCanonicalFile())) {
- writer = ImageIO.getImageWritersByFormatName("png").next();
- writer.setOutput(output);
- IIOImage iioImage = new IIOImage(img, null, null);
- writer.write(null, iioImage, null);
- } finally {
- if (writer != null)
- writer.dispose();
- }
- }
- public static BufferedImage toBufferedImage(Image img) {
- if (img instanceof BufferedImage)
- return (BufferedImage) img;
- BufferedImage bimage = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
- Graphics2D bGr = bimage.createGraphics();
- bGr.drawImage(img, 0, 0, null);
- bGr.dispose();
- return bimage;
- }
Add Comment
Please, Sign In to add comment