java+解析png+gif图片_Java 转换png jpg gif格式图片的相互转换的实现

该博客介绍了如何使用Java的ImageIO类实现PNG, JPG和GIF图片之间的相互转换,提供了简便的方法进行批量处理,适用于Windows和Linux平台。" 112045275,10541392,Python爬虫面试必看:真题解析与实战技巧,"['Python', '爬虫', '数据抓取', 'Scrapy框架', '反爬策略']
摘要由CSDN通过智能技术生成

利用JDK原生支持对png jpg gif格式图片做相互转换,结合脚本就可以达到批量处理的能力,比PS来的快啊!而且是JAVA代码 在Windows和Linux上都可以用。

import java.awt.image.BufferedImage;

import java.io.File;

import javax.imageio.ImageIO;

/**

*

*/

/**

* Created on 2011-5-24 Discription:[convert GIF->JPG GIF->PNG PNG->GIF(X)

* PNG->JPG ]

*

* @param source

* @param formatName

* @param result

* @author:dx[hzdengxu@163.com]

*/

class ImgConverter {

private String[] args;

public static void convert(String source, String formatName, String result) {

try {

File f = new File(source);

f.canRead();

BufferedImage src = ImageIO.read(f);

ImageIO.write(src, formatName, new File(result));

} catch (Exception e) {

e.printStackTrace();

}

}

public ImgConverter(String[] args) {

// TODO Auto-generated constructor stub

this.args = args;

}

public void run() {

if (this.args.length > 2) {

convert(this.args[0], this.args[1], this.args[2]);

}

}

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

new ImgConverter(args).run();

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值