图片格式"/>
ImageIO 支持更多的图片格式
TwelveMonkeys 提供了更多的图片格式用于图片的读写;根据 TwelveMonkeys 提供的文档,其目前支持的图片格式如下:
Plugin | Format | Description | R | W | Metadata | Notes |
---|---|---|---|---|---|---|
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 | Radiance High Dynamic Range RGBE Format | ✔ | - | Standard | |
ICNS | ICNS | Apple Icon Image | ✔ | ✔ | - | |
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 Image Format | ✔ | ✔ | 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 |
此表格来源于github:
GitHub - haraldk/TwelveMonkeys: TwelveMonkeys ImageIO: Additional plug-ins and extensions for Java's ImageIOTwelveMonkeys ImageIO: Additional plug-ins and extensions for Java's ImageIO - GitHub - haraldk/TwelveMonkeys: TwelveMonkeys ImageIO: Additional plug-ins and extensions for Java's ImageIO TwelveMonkeys 所有支持的图片格式,其中JDK中已经原生支持 BMP, JPEG, JPG, GIF, WBMP, PNG等图片格式;除了JDK提供的图片格式,我们经常使用到的图片格式还有 SVG, PSD, TIFF, WebP;下面我们在原来的JDK提供的图片格式上增加对这几种图片格式的扩展。
引入依赖:
<!-- svg格式插件,需要添加batik依赖 -->
<dependency><groupId>com.twelvemonkeys.imageio</groupId><artifactId>imageio-batik</artifactId><version>3.9.4</version>
</dependency>
<dependency><groupId>org.apache.xmlgraphics</groupId><artifactId>batik-all</artifactId><version>1.16</version>
</dependency>
<!-- psd格式插件 -->
<dependency><groupId>com.twelvemonkeys.imageio</groupId><artifactId>imageio-psd</artifactId><version>3.9.4</version>
</dependency>
<!-- tiff格式插件 -->
<dependency><groupId>com.twelvemonkeys.imageio</groupId><artifactId>imageio-tiff</artifactId><version>3.9.4</version>
</dependency>
<!-- webp格式插件 -->
<dependency><groupId>com.twelvemonkeys.imageio</groupId><artifactId>imageio-webp</artifactId><version>3.9.4</version>
</dependency>
下面获取ImageIO支持的图片格式:
String[] readerFormatNames = ImageIO.getReaderFormatNames();
System.out.println("reader: " + Arrays.asList(readerFormatNames));
String[] writerFormatNames = ImageIO.getWriterFormatNames();
System.out.println("writer: " + Arrays.asList(writerFormatNames));
执行的结果如下:
reader: [psd, JPG, tiff, bigtiff, bmp, wbp, gif, SVG, WBMP, PNG, JPEG, BigTIFF, tif, wmf, TIFF, wbmp, jpeg, PSB, PSD, jpg, BMP, WBP, GIF, svg, png, BIGTIFF, webp, TIF, WMF, WEBP, psb]
writer: [psd, PSD, JPG, jpg, tiff, bigtiff, bmp, BMP, gif, GIF, WBMP, png, PNG, BIGTIFF, JPEG, BigTIFF, tif, TIF, TIFF, wbmp, jpeg, psb, PSB]
从上面的打印结果来看,已经支持了SVG, PSD, TIFF, WEBP格式的读取,但仅支持PSD, TIFF格式的写出,不支持SVG, WEBP格式的写出。
更多推荐
ImageIO 支持更多的图片格式
发布评论