机器学习和生物信息学实验室论坛联盟MAchine Learning And Bioinformatics, MALAB
查看: 3933|回复: 1

Java获取图片的尺寸

[复制链接]
发表于 2013-8-29 13:44:37 | 显示全部楼层 |阅读模式
用Java实现获取一张图片的尺寸,示例用下:
  1. import java.awt.image.BufferedImage;
  2. import java.io.File;
  3. import java.io.IOException;
  4. import javax.imageio.ImageIO;

  5. public class img {

  6.         /**
  7.          * example of getting the information(width,height) of a image
  8.          * @throws IOException
  9.          */
  10.         public static void main(String[] args) throws IOException {
  11.                 String imgPath = "D:\\1.jpg"; //the path of the image file
  12.                 BufferedImage bufferedImage = ImageIO.read(new File(imgPath));
  13.                 int width = bufferedImage.getWidth();
  14.                 int height = bufferedImage.getHeight();
  15.                 //the variables width,height is what we want
  16.         }

  17. }
复制代码
代码过于简单,此帖甚虚,欢迎拍砖。
回复

使用道具 举报

发表于 2013-10-11 00:05:00 | 显示全部楼层
这个一般有什么用?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

关注公众号
机器学习和生物信息学实验室联盟

相关侵权、举报、投诉及建议等,请发 E-mail:admin@discuz.vip

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖
关注公众号
返回顶部