成品直播源码,JAVA获取图片的宽、高和大小
成品直播源码,JAVA获取图片的宽、高和大小
如果是本地磁盘文件
File file = new File("C:\\Users\\root\\Desktop\\test.jpg");
BufferedImage bufferedImage = ImageIO.read(new FileInputStream(file));
int height = bufferedImage.getHeight();
int width = bufferedImage.getWidth();
long size = file.length() / 1024;
System.out.println(height);
System.out.println(width);
System.out.println(size);
如果是Spring中通过表单提交的文件
MultipartFile multipartFile = [your multipartfile];
BufferedImage bufferedImage = ImageIO.read(multipartFile.getInputStream());
int height = bufferedImage.getHeight();
int width = bufferedImage.getWidth();
long size = file.getSize() / 1024;
System.out.println(height);
System.out.println(width);
System.out.println(size);
如果需要用本地文件(file)测试spring表单提交文件(multipartfile)需要将file转为MultipartFile
以上就是成品直播源码,JAVA获取图片的宽、高和大小, 更多内容欢迎关注之后的文章