首页 > 代码库 > Java 图片读取与存储

Java 图片读取与存储

 1  @Override 2     public Image myWrite(Image image, String filePath) throws IOException { 3         if (image == null) { 4             throw new IOException("Image is null!"); 5         } 6  7         // create a file 8         File imgFile = new File(filePath + ".bmp"); 9         BufferedImage bmp = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB);10         Graphics2D graph = bmp.createGraphics();11 12         // call the Graphics drawImage method13         graph.drawImage(image, 0, 0, null);14 15         // write to this file16         ImageIO.write(bmp, "bmp", imgFile);17         // read file18         BufferedImage readbmp = ImageIO.read(imgFile);19         return readbmp;20     }