当前位置: 首页 > 工具软件 > TwelveMonkeys > 使用案例 >

java图片处理-twelvemonkeys

汪迪
2023-12-01

java图片处理 - TwelveMonkeys ImageIO

javax.imageio原生支持的格式很少,特殊格式使用 ImageIO.read 获取的为null

可以用getWriterFileSuffixes()查询支持格式

String[] writerFileSuffixes = ImageIO.getWriterFileSuffixes();

原生支持格式

jpg,bmp,gif,png,jpeg,wbmp

TwelveMonkeys ImageIO 是对于 javax.imageio.*包 扩展的插件,这个插件配置后可以添加JRE本身没有覆盖的格式

中文翻译地址

文件格式支持列表

表格来自 TwelveMonkeys 文档

插件格式简介元数据文档
BatikSVGScalable Vector Graphics--Requires Batik
WMFMS Windows Metafile--Requires Batik
BMPBMPMS Windows and IBM OS/2 Device Independent BitmapNative, Standard
CURMS Windows Cursor Format--
ICOMS Windows Icon Format-
HDRHDR辐射高动态范围RGBE格式-Standard
ICNSICNS苹果图标图像-
IFFIFFCommodore Amiga/Electronic Arts Interchange File FormatStandard
JPEGJPEGJoint Photographers Expert GroupNative, Standard
JPEG Lossless-Native, Standard
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图像格式Standard
ThumbsDBThumbs.dbMS Windows Thumbs DB--OLE2 Compound Document based format only
TIFFTIFFAldus/Adobe Tagged Image File FormatNative, Standard
BigTIFFNative, Standard
WebPWebPGoogle WebP Format-Standard
XWDXWDX11 Window Dump Format-Standard

引入该插件后支持的格式

jpg,tpic,tiff,bmp,gif,tf8,png,btiff,tga,tif,btf,jpeg,wbmp

maven依赖

 <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插件

可以通过添加插件,增加imageio支持的文件格式

 类似资料: