/**
     * 读取本地图片到另一个本地文件夹
     * @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]
    }

 

相关文章:

  • 2021-08-20
  • 2021-04-29
  • 2021-06-08
  • 2022-12-23
  • 2019-03-16
  • 2021-07-13
  • 2021-10-04
  • 2022-12-23
猜你喜欢
  • 2021-04-03
  • 2022-12-23
  • 2021-12-04
  • 2021-10-10
  • 2022-12-23
  • 2022-12-23
  • 2021-05-30
相关资源
相似解决方案