java快速获取大图片的分辨率(大图片格式JPG,tiff ,eg)(二)
tring path = "d:\\abc.JPG";
106 File file = new File(path);
107 System.out.println("第1种方法使用的时间:");
108 long s1 = System.currentTimeMillis();
109 System.out.println(getResolution1(file));
110 long l1 = System.currentTimeMillis();
111 System.out.println((l1 - s1)+"ms");
112 System.out.println("******************************");
113 System.out.println("第2种方法使用的时间:");
114 long s2 = System.currentTimeMillis();
115 getResolution2(path);
116 long l2 = System.currentTimeMillis();
117 System.out.println((l2 - s2)+"ms");
118 }
119 }
运行结果:
第1种方法使用的时间:
4867ms
******************************
第2种方法使用的时间:
getFileSuffix:JPG
javax.imageio.ImageIO$ImageReaderIterator@11ddcde
getImageDim:java.awt.Dimension[width=11935,height=8554]
getResolution:11935 x 8554
0ms
注意:由于第一种方法是将图片一次性读入内存所以需要设置JVM的运行内存,具体方法是run图标下拉-》Run Configurations-》VM arguments填入
-Xms256m -Xmx1024m
解释:Dimension类封装单个对象中
组件的宽度和高度(精确到整数)。ImageIO类包含一些用来查找 ImageReader 和 ImageWriter
以及执行简单编码和解码的静态便捷方法。ImageReader用来解析和解码图像的抽象超类。