Advertisement
Guest User

Untitled

a guest
Nov 24th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. public void displayImage()
  2. {
  3.  
  4. System.out.println("displayImage: " + this.imgPath);
  5. ImageIcon picture = new ImageIcon(imgPath);
  6. label = new JLabel("", picture, JLabel.CENTER);
  7.  
  8. JFrame frame = new JFrame() ;
  9. frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  10. frame.setTitle(this.imgPath);
  11. JScrollPane scrollPane = new JScrollPane(label) ;
  12. scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  13. scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
  14. frame.add(scrollPane,BorderLayout.CENTER) ;
  15. frame.pack();
  16. frame.setVisible(true);
  17. }
  18.  
  19. public void decodeImage(String img)
  20. {
  21. try
  22. {
  23. Date date = new Date();
  24. DateFormat df = new SimpleDateFormat("MMddyyhhmmss");
  25.  
  26. this.imgPath = folder+"/"+df.format(date)+".jpg";
  27. System.out.println("decodeImage: " + this.imgPath);
  28. Decoder decoder = Base64.getDecoder();
  29. byte[] decodedBytes = decoder.decode(img);
  30. FileOutputStream fos;
  31. fos = new FileOutputStream(imgPath);
  32. fos.write(decodedBytes);
  33. fos.close();
  34. }
  35. catch (IOException e)
  36. {
  37. System.out.println("errore nella decodifica dell'immagine");
  38. e.printStackTrace();
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement