Advertisement
Guest User

Untitled

a guest
Jun 6th, 2014
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.85 KB | None | 0 0
  1. package image_convert.bmp;
  2.  
  3. import java.awt.Color;
  4. import java.awt.image.BufferedImage;
  5. import java.io.File;
  6. import java.io.IOException;
  7.  
  8. import javax.imageio.ImageIO;
  9.  
  10.  
  11. /**
  12.  * Hello world!
  13.  *
  14.  */
  15. public class App
  16. {  
  17.     static int w_total = 0;
  18.     static int h_total = 0;
  19.     static BufferedImage image = null;
  20.     static int totalTime = 0;
  21.    
  22.     public static void main( String[] args ) throws InterruptedException
  23.     {
  24.      
  25.          try
  26.          {
  27.             image = ImageIO.read(new File("C:/Users/grzes/Desktop/testdata/2.jpg"));
  28.          }
  29.        
  30.          
  31.          catch (IOException e)
  32.          {
  33.             System.out.println("Brak pliku");
  34.          }
  35.          
  36.          long start=System.currentTimeMillis();
  37.          
  38.          PrzetwarzanieObrazu obraz1 = new PrzetwarzanieObrazu(image, 0, 1000);
  39.          PrzetwarzanieObrazu obraz2 = new PrzetwarzanieObrazu(image, 1000, 2000);
  40.          PrzetwarzanieObrazu obraz3 = new PrzetwarzanieObrazu(image, 2000, 3000);
  41.          PrzetwarzanieObrazu obraz4 = new PrzetwarzanieObrazu(image, 4000, 5000);
  42.          PrzetwarzanieObrazu obraz5 = new PrzetwarzanieObrazu(image, 5000, image.getWidth());
  43.          
  44.          /* threads*/
  45.          obraz1.start();
  46.          obraz2.start();
  47.          obraz3.start();
  48.          obraz4.start();
  49.          obraz5.start();
  50.          obraz1.join();obraz2.join();obraz3.join();obraz4.join();obraz5.join();
  51.          
  52.          
  53.          
  54.  
  55.          long stop=System.currentTimeMillis();
  56.  
  57.             try
  58.             {
  59.                 ImageIO.write(image, "jpg", new File("C:/Users/grzes/Desktop/testdata/result.jpg"));
  60.                 System.out.println("End, saved");
  61.             }
  62.             catch (IOException e)
  63.             {
  64.                 System.out.println("Error while saving");
  65.             }
  66.          
  67.          System.out.println("Total time: " + (stop-start));
  68.     }
  69.    
  70.     public static void setObraz(int i, int j, Color bw_color)
  71.     {
  72.         image.setRGB(i, j, bw_color.getRGB());
  73.     }
  74.    
  75.    
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement