|
用Java实现获取一张图片的尺寸,示例用下:- import java.awt.image.BufferedImage;
- import java.io.File;
- import java.io.IOException;
- import javax.imageio.ImageIO;
- public class img {
- /**
- * example of getting the information(width,height) of a image
- * @throws IOException
- */
- public static void main(String[] args) throws IOException {
- String imgPath = "D:\\1.jpg"; //the path of the image file
- BufferedImage bufferedImage = ImageIO.read(new File(imgPath));
- int width = bufferedImage.getWidth();
- int height = bufferedImage.getHeight();
- //the variables width,height is what we want
- }
- }
复制代码 代码过于简单,此帖甚虚,欢迎拍砖。 |
|