从二进制获取图像尺寸和图像大小 [英] Get Image Dimension and Image Size from Binary

查看:102
本文介绍了从二进制获取图像尺寸和图像大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个需要一些图像处理的项目上.

I am working on a project which requires some image processing.

Web客户端将提交jpg,png,gif tif格式的图像.服务器端需要找出图像的尺寸和大小.

The web client is going to submit image of format jpg, png, gif tif. The server side needs to find out the dimension and the size of the image.

我可以看到一些Java类通过处理图像文件来实现此目的.有什么方法/库可以用来避免将二进制文件保存到文件中并仍然获取尺寸?

I can see some of the Java classes achieve this by processing an image file. Is there any way/library I can use to avoid saving the binary into a file and still get the dimension?

非常感谢

推荐答案

File imageFile = new File("Pic.jpg");

double bytes = imageFile.length();

System.out.println("File Size: " + String.format("%.2f", bytes/1024) + "kb");

try{

    BufferedImage image = ImageIO.read(imageFile);
    System.out.println("Width: " + image.getWidth());
    System.out.println("Height: " + image.getHeight());

} catch (Exception ex){
    ex.printStackTrace();
}

这篇关于从二进制获取图像尺寸和图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆