Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. public static void main(String[] args) throws FileNotFoundException {
  2. String path ="C:/Users/Nitendo/Desktop/Snow.ppm";
  3. FileReader fReader = new FileReader(path);
  4. Scanner inFile = new Scanner(fReader);
  5. String p3=inFile.nextLine();
  6. String program=inFile.nextLine();
  7. int rows=inFile.nextInt();
  8. int cols=inFile.nextInt();
  9. int maxValue=inFile.nextInt();
  10. int[][] red = new int [rows][cols];
  11. int[][] green = new int [rows][cols];
  12. int[][] blue = new int [rows][cols];
  13. for (int c = 0; c<cols;c++){
  14. for(int r =0; r<rows; r++){
  15. red[r][c]=inFile.nextInt();
  16. green[r][c]=inFile.nextInt();
  17. blue[r][c]=inFile.nextInt();
  18. }
  19. }
  20.  
  21. inFile.close();
  22.  
  23. BufferedImage img = new BufferedImage(rows, cols, BufferedImage.TYPE_3BYTE_BGR);
  24. for (int c = 0; c<cols;c++){
  25. for(int r =0; r<rows; r++){
  26. int rgb = red[r][c];
  27. rgb=(rgb<<8)+green[r][c];
  28. rgb=(rgb<<8)+blue[r][c];
  29. img.setRGB(r, c, rgb);
  30. }
  31. }
  32.  
  33. JLabel jLabel=new JLabel(new ImageIcon(img));
  34. JPanel jPanel=new JPanel();
  35. jPanel.add(jLabel);
  36.  
  37. JFrame r = new JFrame();
  38. r.setSize(rows+100, cols+100);
  39. r.add(jPanel);
  40. r.setVisible(true);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement