可以用getWriterFileSuffixes()查询支持格式
String[] writerFileSuffixes = ImageIO.getWriterFileSuffixes();
原生支持格式
jpg,bmp,gif,png,jpeg,wbmp
TwelveMonkeys ImageIO 是对于 javax.imageio.*包 扩展的插件,这个插件配置后可以添加JRE本身没有覆盖的格式
表格来自 TwelveMonkeys 文档
插件 | 格式 | 简介 | 读 | 写 | 元数据 | 文档 |
---|---|---|---|---|---|---|
Batik | SVG | Scalable Vector Graphics | ✔ | - | - | Requires Batik |
WMF | MS Windows Metafile | ✔ | - | - | Requires Batik | |
BMP | BMP | MS Windows and IBM OS/2 Device Independent Bitmap | ✔ | ✔ | Native, Standard | |
CUR | MS Windows Cursor Format | ✔ | - | - | ||
ICO | MS Windows Icon Format | ✔ | ✔ | - | ||
HDR | HDR | 辐射高动态范围RGBE格式 | ✔ | - | Standard | |
ICNS | ICNS | 苹果图标图像 | ✔ | ✔ | - | |
IFF | IFF | Commodore Amiga/Electronic Arts Interchange File Format | ✔ | ✔ | Standard | |
JPEG | JPEG | Joint Photographers Expert Group | ✔ | ✔ | Native, Standard | |
JPEG Lossless | ✔ | - | Native, Standard | |||
PCX | PCX | ZSoft Paintbrush Format | ✔ | - | Standard | |
DCX | Multi-page PCX fax document | ✔ | - | Standard | ||
PICT | PICT | Apple QuickTime Picture Format | ✔ | ✔ | Standard | |
PNTG | Apple MacPaint Picture Format | ✔ | - | Standard | ||
PNM | PAM | NetPBM Portable Any Map | ✔ | ✔ | Standard | |
PBM | NetPBM Portable Bit Map | ✔ | - | Standard | ||
PGM | NetPBM Portable Grey Map | ✔ | - | Standard | ||
PPM | NetPBM Portable Pix Map | ✔ | ✔ | Standard | ||
PFM | Portable Float Map | ✔ | - | Standard | ||
PSD | PSD | Adobe Photoshop Document | ✔ | (✔) | Native, Standard | |
PSB | Adobe Photoshop Large Document | ✔ | - | Native, Standard | ||
SGI | SGI | Silicon Graphics Image Format | ✔ | - | Standard | |
TGA | TGA | Truevision TGA图像格式 | ✔ | ✔ | Standard | |
ThumbsDB | Thumbs.db | MS Windows Thumbs DB | ✔ | - | - | OLE2 Compound Document based format only |
TIFF | TIFF | Aldus/Adobe Tagged Image File Format | ✔ | ✔ | Native, Standard | |
BigTIFF | ✔ | ✔ | Native, Standard | |||
WebP | WebP | Google WebP Format | ✔ | - | Standard | |
XWD | XWD | X11 Window Dump Format | ✔ | - | Standard |
引入该插件后支持的格式
jpg,tpic,tiff,bmp,gif,tf8,png,btiff,tga,tif,btf,jpeg,wbmp
<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-jpeg</artifactId>
<version>3.9.4</version>
</dependency>
<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-tiff</artifactId>
<version>3.9.4</version>
</dependency>
<dependency>
<groupId>com.twelvemonkeys.servlet</groupId>
<artifactId>servlet</artifactId>
<version>3.9.4</version>
</dependency>
<dependency>
<groupId>com.twelvemonkeys.servlet</groupId>
<artifactId>servlet</artifactId>
<version>3.9.4</version>
<classifier>jakarta</classifier>
</dependency>
tga图片等特殊格式需要额外添加本地依赖
<dependency>
<groupId>javax.imageio</groupId>
<artifactId>tga</artifactId>
<version>3.9.4</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/jar/imageio-tga-3.9.4.jar</systemPath>
</dependency>
tga图片转jpg
try {
BufferedImage bufferegImage = ImageIO.read(new File("E:\\input.tga"));
ImageIO.write(bufferegImage, "png", new File("E:output.jpg"));
}catch (Exception e){
System.out.println(e.getMessage());
}
可以通过添加插件,增加imageio支持的文件格式