ImageIO类说明

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/wangdajiao/article/details/52550151

最近的项目中遇到ImageIO,因此记录下这个类的用法
一、ImageIO:
这个类中的方法都是静态方法,可以用来进行简单的图片IO操作
1、读入的三种方法
public static BufferedImage read(File input)

File file = new File("/Users/xixi/Documents/aaa.png");
BufferedImage bu = ImageIO.read(file);
 
 
  • 1
  • 2

public static BufferedImage read(InputStream input)

public static BufferedImage read(ImageInputStream stream)

2、RenderedImage接口的子类是BufferedImage,因此在这里可以直接出传入BufferedImage的实例化对象,将BufferedImage对象直接写出指定输出流

public static boolean write(RenderedImage im,String formatName,File output)

public static boolean write(RenderedImage im, String formatName,OutputStream output)

public static boolean write(RenderedImage im, String formatName,ImageOutputStream output)

复制图片代码

public class Test {
    public static void main(String[] args) {
        File out = new File("/Users/wangjue/DownLoads/1.jpg");
        //将图片写入ImageIO流
        try {
            BufferedImage img = ImageIO.read(out);
        //将图片写出到指定位置(复制图片)
            OutputStream ops = new FileOutputStream(new File("/Users/wangjue/DownLoads/1(1).jpg"));
            ImageIO.write(img, "jpg", ops);         
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}

 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
            <link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-095d4a0b23.css" rel="stylesheet">
                </div>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值