首页 > 编程语言 > 详细

Java读取图片像素和大小

时间:2015-07-09 14:40:56      阅读:418      评论:0      收藏:0      [点我收藏+]
package com.aa.promotion.dao.generalize;


import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.channels.FileChannel;


import javax.imageio.ImageIO;


public class UmpGeneralizeDAO {


public static void main(String[] args) {
File file = new File("E:\\test.jpg");
FileChannel fc = null;
if(file.exists() && file.isFile()){
try {
FileInputStream fs = new FileInputStream(file);
fc = fs.getChannel();
System.out.println(fc.size() + "-----fc.size()");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println(file.length() + "-----file.length  B");
System.out.println(file.length() * 1024 + "-----file.length  kb");
BufferedImage bi = null;
try {
bi = ImageIO.read(file);
} catch (IOException e) {
e.printStackTrace();
}

int width = bi.getWidth();
int height = bi.getHeight();

System.out.println("宽:像素-----" + width + "高:像素"  + height);


}
}


获取到的图片大小默认为B

版权声明:本文为博主原创文章,未经博主允许不得转载。

Java读取图片像素和大小

原文:http://blog.csdn.net/wy634379160/article/details/46814787

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!