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 method 13 graph.drawImage(image, 0, 0, null); 14 15 // write to this file 16 ImageIO.write(bmp, "bmp", imgFile); 17 // read file 18 BufferedImage readbmp = ImageIO.read(imgFile); 19 return readbmp; 20 }
Java 图片读取与存储
时间: 2024-10-05 23:58:15