ImageIO 支持更多的图片格式

TwelveMonkeys 提供了更多的图片格式用于图片的读写;根据 TwelveMonkeys 提供的文档,其目前支持的图片格式如下:

PluginFormatDescriptionRWMetadataNotes
BatikSVGScalable Vector Graphics--Requires Batik
WMFMS Windows Metafile--Requires Batik
BMPBMPMS Windows and IBM OS/2 Device Independent BitmapNativeStandard
CURMS Windows Cursor Format--
ICOMS Windows Icon Format-
HDRHDRRadiance High Dynamic Range RGBE Format-Standard
ICNSICNSApple Icon Image-
IFFIFFCommodore Amiga/Electronic Arts Interchange File FormatStandard
JPEGJPEGJoint Photographers Expert GroupNativeStandard
JPEG Lossless-NativeStandard
PCXPCXZSoft Paintbrush Format-Standard
DCXMulti-page PCX fax document-Standard
PICTPICTApple QuickTime Picture FormatStandard
PNTGApple MacPaint Picture Format-Standard
PNMPAMNetPBM Portable Any MapStandard
PBMNetPBM Portable Bit Map-Standard
PGMNetPBM Portable Grey Map-Standard
PPMNetPBM Portable Pix MapStandard
PFMPortable Float Map-Standard
PSDPSDAdobe Photoshop Document(✔)Native, Standard
PSBAdobe Photoshop Large Document-Native, Standard
SGISGISilicon Graphics Image Format-Standard
TGATGATruevision TGA Image FormatStandard
ThumbsDBThumbs.dbMS Windows Thumbs DB--OLE2 Compound Document based format only
TIFFTIFFAldus/Adobe Tagged Image File FormatNativeStandard
BigTIFFNativeStandard
WebPWebPGoogle WebP Format-Standard
XWDXWDX11 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 ImageIOhttps://github.com/haraldk/TwelveMonkeys以上是 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格式的写出。 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值