Imaging (previously called Sanselan)读取图像信息

Imaging (previously called Sanselan)是Apache开源组织提供的用于操作图像的工具包。我们可以通过该包中提供的Sanselan很方便的获取图片信息以及存储保存工作。这个项目目前还属于孵化中的项目,尚未正式发布,我们直接上代码:

package com.gujin.sanselan;

import java.io.File;

import org.apache.sanselan.ImageInfo;
import org.apache.sanselan.Sanselan;
import org.junit.Test;

public class SanselanTest {
   @Test
   public void test() throws Exception
   {
      File imageFile = new File("file/bg.png");
      // 判断文件是否存在
      System.out.println(Sanselan.hasImageFileExtension(imageFile));
      System.out.println("=======================================");
      // 获得图片结构描述
      System.out.println(Sanselan.dumpImageFile(imageFile));
      System.out.println("=======================================");
      // 获得图片信息
      ImageInfo imageInfo = Sanselan.getImageInfo(imageFile);
      System.out.println(imageInfo.getColorTypeDescription());
      System.out.println(imageInfo.getFormatName());
      System.out.println(imageInfo.getMimeType());
      System.out.println("=======================================");
      // 获得图片尺寸
      System.out.println(Sanselan.getImageSize(imageFile));
      System.out.println("=======================================");
      System.out.println(Sanselan.guessFormat(imageFile));
   }
}

运行结果如下:

true
=======================================
Format Details: Png
Bits Per Pixel: 32
Comments: 0
Format: PNG
Format Name: PNG Portable Network Graphics
Compression Algorithm: PNG Filter
Height: 285
MimeType: image/png
Number Of Images: 1
Physical Height Dpi: -1
Physical Height Inch: -1.0
Physical Width Dpi: -1
Physical Width Inch: -1.0
Width: 286
Is Progressive: false
Is Transparent: false
Color Type: RGB
Uses Palette: false
Color: RGB w/ alpha
chunks: 13
   0: : 'IHDR'
   1: : 'IDAT'
   2: : 'IDAT'
   3: : 'IDAT'
   4: : 'IDAT'
   5: : 'IDAT'
   6: : 'IDAT'
   7: : 'IDAT'
   8: : 'IDAT'
   9: : 'IDAT'
   10: : 'IDAT'
   11: : 'IDAT'
   12: : 'IEND'


=======================================
RGB
PNG Portable Network Graphics
image/png
=======================================
java.awt.Dimension[width=286,height=285]
=======================================
{PNG: PNG}

你可能感兴趣的:(apache,图片,imaging,Sanselan)