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获取图片像素距离_Java读取图片像素和大小
最新推荐文章于 2024-07-08 03:12:29 发布