Sanselan - Java图像处理库


Apache
跨平台
Java

软件简介

Sanselan 是一个纯 Java
的图形库,可以读写各种格式的图像文件,包括快速解析图片信息例如大小/颜色/icc以及元数据等。尽管因为是Java开发的,在处理速度上会稍微慢一
些,但具备良好的可移植性。虽然尚未发布1.0 版本,但是已经有多个项目在使用 Sanselan 来处理图像文件。

该项目目前还是 Apache 组织的一个孵化项目。

JavaDoc: http://www.apache.org/dist/incubator/sanselan/javadoc/

示例代码:

File file = someFile;
BufferedImage image_3 = Sanselan.getBufferedImage(file);
InputStream is = someInputStream;
BufferedImage image_4 = Sanselan.getBufferedImage(is);

// Write an image.
BufferedImage image = someImage;
File dst = someFile;
ImageFormat format = ImageFormat.IMAGE_FORMAT_PNG;
Map optional_params = new Hashtable();
Sanselan.writeImage(image, dst, format, optional_params);

OutputStream os = someOutputStream;
Sanselan.writeImage(image, os, format, optional_params);

// get the image’s embedded ICC Profile, if it has one.
byte icc_profile_bytes[] = Sanselan.getICCProfileBytes(imageBytes);

ICC_Profile icc_profile = Sanselan.getICCProfile(imageBytes);

// get the image’s width and height.
Dimension d = Sanselan.getImageSize(imageBytes);

// get all of the image’s info (ie. bits per pixel, size, transparency, etc.)
ImageInfo image_info = Sanselan.getImageInfo(imageBytes);

if (image_info.getColorType() == ImageInfo.COLOR_TYPE_GRAYSCALE)
System.out.println(“Grayscale image.”);
if (image_info.getHeight() > 1000)
System.out.println(“Large image.”);

// try to guess the image’s format.
ImageFormat image_format = Sanselan.guessFormat(imageBytes);
image_format.equals(ImageFormat.IMAGE_FORMAT_PNG);

// get all metadata stored in EXIF format (ie. from JPEG or TIFF).
// org.w3c.dom.Node node = Sanselan.getMetadataObsolete(imageBytes);
IImageMetadata metdata = Sanselan.getMetadata(imageBytes);

// print a dump of information about an image to stdout.
Sanselan.dumpImageFile(imageBytes);

// get a summary of format errors.
FormatCompliance format_compliance = Sanselan
.getFormatCompliance(imageBytes);