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 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     }

 

posted @ 2014-08-12 01:15  玉做的树  阅读(852)  评论(0编辑  收藏  举报