今天网上下载了几个webp格式的图片,想转换成png,下载的工具转换都收费,用Java怒写程序,自己转换

        今天网上下载了几个webp格式的图片,想转换成png,下载的工具转换都收费,用Java怒写程序,自己转换,说干就干。

添加依赖

		<!-- 支持图片格式 WebP -->
		<dependency>
			<groupId>org.sejda.imageio</groupId>
			<artifactId>webp-imageio</artifactId>
			<version>0.1.6</version>
		</dependency>

代码

    public static void main(String[] args) {
        try {
            String directoryPath = "C:\\Users\\Administrator\\Desktop\\abc";
            File directory = new File(directoryPath);
            if (directory.exists() && directory.isDirectory()) {
                File[] files = directory.listFiles();
                int i = 1;
                for (File file : files) {
                    // 读取WebP图片文件
                    BufferedImage webpImage = ImageIO.read(file);

                    // 输出PNG图片文件,注意指定格式名称,即使文件扩展名不是.png
                    ImageIO.write(webpImage, "png", new File(directoryPath+"\\"+(i++)+".png"));
                }

                System.out.println("WebP to PNG conversion completed successfully.");
            }

        } catch (IOException e) {
            System.out.println("Error converting WebP to PNG: " + e.getMessage());
        }
    }

        这回心情舒畅,第一次感觉自己干的工作,用到了自己实际生活中,非常哇塞的程序员。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值