1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > java webp图片转换为png或jpg

java webp图片转换为png或jpg

时间:2023-05-20 07:09:12

相关推荐

java webp图片转换为png或jpg

java webp图片转换为png或jpg

webp格式图片说明

WebP,是一种支持有损压缩和无损压缩的图片文件格式,派生自图像编码格式 VP8。根据 Google 的测试,无损压缩后的 WebP 比 PNG 文件少了 45% 的文件大小,即使这些 PNG 文件经过其他压缩工具压缩之后,WebP 还是可以减少 28% 的文件大小。

淘宝上的图片就是webp格式。

webp转png

maven依赖

<dependency><groupId>org.sejda.imageio</groupId><artifactId>webp-imageio</artifactId><version>0.1.6</version></dependency>

转码工具类

import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import javax.imageio.ImageIO;import javax.imageio.ImageReader;import javax.imageio.stream.FileImageInputStream;import com.luciad.imageio.webp.WebPReadParam;public class WebpUtil {public static void main(String[] args) throws IOException {String path="C:\\Users\\admin\\Pictures\\webp\\123.webp";webpToPng(path, "C:\\Users\\admin\\Pictures\\webp\\1234.png");System.out.println("ok");}public static void webpToPng(String webpPath, String pngPath) throws IOException {// Obtain a WebP ImageReader instanceImageReader reader = ImageIO.getImageReadersByMIMEType("image/webp").next();// Configure decoding parametersWebPReadParam readParam = new WebPReadParam();readParam.setBypassFiltering(true);// Configure the input on the ImageReaderreader.setInput(new FileImageInputStream(new File(webpPath)));// Decode the imageBufferedImage image = reader.read(0, readParam);// the `png` can use `jpg`ImageIO.write(image, "png", new File(pngPath));}}

相关文章(图片格式转换)

神奇手ImageMagick学习笔记(多种图片格式转换和色彩空间转换)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。