ImageIO 支持webp格式

TwelveMonkeys 提供了很多图片格式的支持,其中也包括了webp,但是其仅支持webp格式的读取,不支持webp格式的写出,这样的话如果想把图片转换成webp格式的图片就没办法实现了;下面我们使用 webp-imageio-core 对ImageIO图片格式进行扩展,使其能够支持webp图片格式的读写;

首先我们需要引入jar包:

下载地址: Release v0.1.3 Release · nintha/webp-imageio-core · GitHubJava Image I/O reader and writer for the Google WebP image format without system native libs - Release v0.1.3 Release · nintha/webp-imageio-corehttps://github.com/nintha/webp-imageio-core/releases/tag/v0.1.3

 下载好jar包之后,我们把jar包放在项目的lib目录下,使用maven进行引入:

<dependency>
    <groupId>com.github.nintha</groupId>
    <artifactId>webp-imageio-core</artifactId>
    <version>0.1.3</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/lib/webp-imageio-core-0.1.3.jar</systemPath>
</dependency>

引入之后,我们可以使用代码查看一下ImageIO支持的读写图片的格式:

List<String> readerFormatNames = Arrays.asList(ImageIO.getReaderFormatNames());
System.out.println("readers: " + readerFormatNames);
List<String> writerFormatNames = Arrays.asList(ImageIO.getWriterFormatNames());
System.out.println("writers: " + writerFormatNames);

运行的结果如下:

readers: [JPG, jpg, tiff, bmp, BMP, pcx, PCX, gif, GIF, WBMP, png, PNG, raw, RAW, JPEG, webp, pnm, PNM, tif, TIF, TIFF, WebP, wbmp, jpeg]
writers: [JPG, jpg, tiff, bmp, BMP, pcx, PCX, gif, GIF, WBMP, png, PNG, raw, RAW, JPEG, webp, pnm, PNM, tif, TIF, TIFF, WebP, jpeg, wbmp]

从运行的结果来看,读写图片已经支持了webp格式,这样就可以进行webp格式与其他的图片格式进行相互转换了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值