ImageIO 操作图片
/** * 读取本地图片到另一个本地文件夹 * @throws IOException */ public void copeImageToOtherFolder() throws IOException { File file = new File(imgPath+"img_1.jpg"); Image image = ImageIO.read(file); BufferedImage bufferedImage = new BufferedImage(image.getWidth(null),image.getHeight(null),BufferedImage.TYPE_INT_RGB); /**下面这个是画板*/ Graphics g = bufferedImage.getGraphics(); // Image x坐标 y坐标 图片宽度 图片高度 ** g.drawImage(image,0,0,image.getWidth(null),image.getHeight(null),null); g.dispose(); ImageIO.write(bufferedImage,"png",new File(imgPath+"new\\"+ UUID.randomUUID().toString().substring(0,8)+".png")); } /** * 获取ImageIO读取和写取的图片格式 */ public void formatImageName(){ String[] str = ImageIO.getReaderFormatNames(); //可读取的图片格式 System.out.println(Arrays.asList(str));//[BMP, bmp, jpg, JPG, wbmp, jpeg, png, PNG, JPEG, WBMP, GIF, gif] //可写的图片格式 String[] str1 = ImageIO.getWriterFormatNames(); System.out.println(Arrays.asList(str1));//[BMP, bmp, jpg, JPG, wbmp, jpeg, png, PNG, JPEG, WBMP, GIF, gif] }