我正在尝试在Image Processor
中构建一个与Java
图像一起使用的Black-White
应用图片。因此我的应用程序应该读取许多黑白图像,但读取图像的时间非常长因为图像以JPEG格式存储并且尺寸很大。
问题:用最佳时间存储Java中可读的黑白图像的最佳Image Format
(不是TXT)是什么?
答案 0 :(得分:1)
代码:
import javax.imageio.*;
import java.awt.image.*;
import java.io.*;
public class timedimageread
{
public static void main(String[] args)
{
BufferedImage img;
long startTime;
long endTime;
startTime = System.currentTimeMillis();
try
{
img = ImageIO.read(new File("blackandwhite.jpg"));
}
catch(IOException e){}
endTime = System.currentTimeMillis();
System.out.println("jpg: " + (endTime - startTime) );
startTime = System.currentTimeMillis();
try
{
img = ImageIO.read(new File("blackandwhite.bmp"));
}
catch(IOException e){}
endTime = System.currentTimeMillis();
System.out.println("bmp: " + (endTime - startTime) );
startTime = System.currentTimeMillis();
try
{
img = ImageIO.read(new File("blackandwhite.gif"));
}
catch(IOException e){}
endTime = System.currentTimeMillis();
System.out.println("gif: " + (endTime - startTime) );
startTime = System.currentTimeMillis();
try
{
img = ImageIO.read(new File("blackandwhite.png"));
}
catch(IOException e){}
endTime = System.currentTimeMillis();
System.out.println("png: " + (endTime - startTime) );
startTime = System.currentTimeMillis();
try
{
img = ImageIO.read(new File("blackandwhite.tif"));
}
catch(IOException e){}
endTime = System.currentTimeMillis();
System.out.println("tif: " + (endTime - startTime) );
startTime = System.currentTimeMillis();
try
{
img = ImageIO.read(new File("blackandwhite.jpg"));
}
catch(IOException e){}
endTime = System.currentTimeMillis();
System.out.println("jpg: " + (endTime - startTime) );
startTime = System.currentTimeMillis();
try
{
img = ImageIO.read(new File("blackandwhite.bmp"));
}
catch(IOException e){}
endTime = System.currentTimeMillis();
System.out.println("bmp: " + (endTime - startTime) );
startTime = System.currentTimeMillis();
try
{
img = ImageIO.read(new File("blackandwhite.gif"));
}
catch(IOException e){}
endTime = System.currentTimeMillis();
System.out.println("gif: " + (endTime - startTime) );
startTime = System.currentTimeMillis();
try
{
img = ImageIO.read(new File("blackandwhite.png"));
}
catch(IOException e){}
endTime = System.currentTimeMillis();
System.out.println("png: " + (endTime - startTime) );
startTime = System.currentTimeMillis();
try
{
img = ImageIO.read(new File("blackandwhite.tif"));
}
catch(IOException e){}
endTime = System.currentTimeMillis();
System.out.println("tif: " + (endTime - startTime) );
startTime = System.currentTimeMillis();
try
{
img = ImageIO.read(new File("blackandwhite.jpg"));
}
catch(IOException e){}
endTime = System.currentTimeMillis();
System.out.println("jpg: " + (endTime - startTime) );
startTime = System.currentTimeMillis();
try
{
img = ImageIO.read(new File("blackandwhite.bmp"));
}
catch(IOException e){}
endTime = System.currentTimeMillis();
System.out.println("bmp: " + (endTime - startTime) );
startTime = System.currentTimeMillis();
try
{
img = ImageIO.read(new File("blackandwhite.gif"));
}
catch(IOException e){}
endTime = System.currentTimeMillis();
System.out.println("gif: " + (endTime - startTime) );
startTime = System.currentTimeMillis();
try
{
img = ImageIO.read(new File("blackandwhite.png"));
}
catch(IOException e){}
endTime = System.currentTimeMillis();
System.out.println("png: " + (endTime - startTime) );
startTime = System.currentTimeMillis();
try
{
img = ImageIO.read(new File("blackandwhite.tif"));
}
catch(IOException e){}
endTime = System.currentTimeMillis();
System.out.println("tif: " + (endTime - startTime) );
}
}
输出: jpg:156 bmp:0 gif:16 png:16 tif:0 jpg:31 bmp:0 gif:16 png:0 tif:15 jpg:16 bmp:0 gif:0 png:16 tif:0
你可以扩展代码或使用更大的图片来获得更好的结果,但我的假设是.bmp(我使用了256色,但你可以减少它)最快速的过程。