Guest User

Untitled

a guest
Jul 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. public Image getImage(File file) throws FileNotFoundException {
  2. sun.awt.shell.ShellFolder sf = sun.awt.shell.ShellFolder.getShellFolder(file);
  3. return new ImageIcon(sf.getIcon(true)).getImage();
  4. }
  5.  
  6. FileSystemView.getFileSystemView().getSystemIcon(file);
  7.  
  8. public static void writePNG(File f, BufferedImage img) throws Exception {
  9. ImageWriter writer = null;
  10. f.createNewFile();
  11. try(FileImageOutputStream output = new FileImageOutputStream(f.getCanonicalFile())) {
  12. writer = ImageIO.getImageWritersByFormatName("png").next();
  13. writer.setOutput(output);
  14. IIOImage iioImage = new IIOImage(img, null, null);
  15. writer.write(null, iioImage, null);
  16. } finally {
  17. if (writer != null)
  18. writer.dispose();
  19. }
  20. }
  21.  
  22. public static BufferedImage toBufferedImage(Image img) {
  23. if (img instanceof BufferedImage)
  24. return (BufferedImage) img;
  25. BufferedImage bimage = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
  26. Graphics2D bGr = bimage.createGraphics();
  27. bGr.drawImage(img, 0, 0, null);
  28. bGr.dispose();
  29. return bimage;
  30. }
Add Comment
Please, Sign In to add comment