Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
T

TwelveMonkeys

> 编程语言
Open source

TwelveMonkeys ImageIO: Additional plug-ins and extensions for Java's ImageIO

2.1K stars0 likes0 views
WebsiteGitHub

About

TwelveMonkeys ImageIO: Additional plug-ins and extensions for Java's ImageIO

About

TwelveMonkeys ImageIO provides extended image file format support for the Java platform, through plugins for the javax.imageio.* package.

The main goal of this project is to provide support for file formats not covered by the JDK. Support for these formats is important, to be able to read data found "in the wild", as well as to maintain access to data in legacy formats. As there is lots of legacy data out there, we see the need for open implementations of readers for popular formats.


File formats supported

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 ✔ ✔ -
DDS DDS MS Direct Draw Surface Format ✔ - Standard
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 Arbitrary 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

Important note on using Batik: Please read The Apache™ XML Graphics Project - Security, and make sure you use an updated and secure version.

Note that GIF, PNG and WBMP formats are already supported through the ImageIO API, using the JDK standard plugins. For BMP, JPEG, and TIFF formats the TwelveMonkeys plugins provides extended format support and additional features.

Basic usage

Most of the time, all you need to do is simply include the plugins in your project and write:

java
BufferedImage image = ImageIO.read(file);

This will load the first image of the file, entirely into memory.

The basic and simplest form of writing is:

java
if (!ImageIO.write(image, format, file)) {
   // Handle image not written case
}

This will write the entire image into a single file, using the default settings for the given format.

The plugins are discovered automatically at run time. See the FAQ for more info on how this mechanism works.

Advanced usage

If you need more control of read parameters and the reading process, the common idiom for reading is something like:

…

Query the reader for source image dimensions using reader.getWidth(n) and reader.getHeight(n) without reading the entire image into memory first.

It's also possible to read multiple images from the same file in a loop, using reader.getNumImages().

If you need more control of write parameters and the writing process, the common idiom for writing is something like:

…

For more advanced usage, and information on how to use the ImageIO API, I suggest you read the Java Image I/O API Guide from Oracle.

Adobe Clipping Path support

java
import com.twelvemonkeys.imageio.path.Paths;

...

try (ImageInputStream stream = ImageIO.createImageInputStream(new File("image_with_path.jpg")) {
    BufferedImage image = Paths.readClipped(stream);

    // Do something with the clipped image...
}

See Adobe Clipping Path support on the Wiki for more details and example code.

Using the ResampleOp

The library comes with a resampling (image resizing) operation, that contains many different algorithms to provide excellent results at reasonable speed.

java
import com.twelvemonkeys.image.ResampleOp;

...

BufferedImage input = ...; // Image to resample
int width, height = ...; // new width/height

BufferedImageOp resampler = new ResampleOp(width, height, ResampleOp.FILTER_LANCZOS); // A good default filter, see class documentation for more info
BufferedImage output = resampler.filter(input, null);

Using the DiffusionDither

The library comes with a dithering operation, that can be used to convert BufferedImages to IndexColorModel using Floyd-Steinberg error-diffusion dither.

java
import com.twelvemonkeys.image.DiffusionDither;

...

BufferedImage input = ...; // Image to dither

BufferedImageOp ditherer = new DiffusionDither();
BufferedImage output = ditherer.filter(input, null);

Working with damaged images

When using the normal patterns for loading images, trying to load a damaged image will result in an IOException being thrown.

java
BufferedImage image = null;
try {
    image = ImageIO.read(file);
} catch (IOException exception) {
    // Handle, log a warning/error etc
}

In this scenario, if the image is damaged, and ImageIO.read throws an exception, image is still null - it's not possible for a function to both return a

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Javabmpicc-profilesicnsiff

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言