第四十三篇:Imaging (previously called Sanselan)读取图像信息

来源:互联网 发布:网络借贷 金融机构 编辑:程序博客网 时间:2024/05/08 14:37

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));   }}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

运行结果如下:

true=======================================Format Details: PngBits Per Pixel: 32Comments: 0Format: PNGFormat Name: PNG Portable Network GraphicsCompression Algorithm: PNG FilterHeight: 285MimeType: image/pngNumber Of Images: 1Physical Height Dpi: -1Physical Height Inch: -1.0Physical Width Dpi: -1Physical Width Inch: -1.0Width: 286Is Progressive: falseIs Transparent: falseColor Type: RGBUses Palette: falseColor: RGB w/ alphachunks: 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'=======================================RGBPNG Portable Network Graphicsimage/png=======================================java.awt.Dimension[width=286,height=285]======================================={PNG: PNG}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
原创粉丝点击