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}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值