2015-01-22 2 views
0

Я пытаюсь создать Image Processor Изображение приложения в Java, которое работает с Black-White Изображение. Поэтому мое приложение должно читать много черно-белых изображений, но время чтения изображения очень велико. Изображения хранятся в формате JPEG и имеют большой размер.Лучший формат изображения для хранения двоичного изображения в Java

Вопрос: Что является лучшим Image Format (а не TXT) для хранения черно-белого изображения, которое можно было прочитать на Java с лучшим временем?

+0

Это не Java, а вопрос программирования – ControlAltDel

ответ

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 ВМР: 0 GIF: 16 ​​ PNG: 16 TIF: 0 JPG: 31 ВМР: 0 GIF: 16 ​​ PNG: 0 TIF: 15 JPG: 16 ВМР: 0 GIF: 0 PNG: 16 TIF: 0

Вы можете расширить код или использовать увеличенное изображение, чтобы получить лучшие результаты, но мое предположение заключается в том, что .bmp (я использовал 256 цветов, но вы могли бы уменьшить это), процессы быстро становятся наиболее надежными.

+0

Этот ответ непонятен. Что делает этот код точно? –

+0

раз чтение файла в буфер. – brettmichaelgreen