import java.awt.*; import java.awt.image.*; import javax.swing.*; public class Test { public static void main(String[] args){ for(int i = 0; i < 30; i ++){ display(resize(getRandomFrame(),500,500)); } } private static JFrame frame; private static JLabel label; public static void display(BufferedImage image){ if(frame==null){ frame=new JFrame(); frame.setTitle("stained_image"); frame.setSize(image.getWidth(), image.getHeight()); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); label=new JLabel(); label.setIcon(new ImageIcon(image)); frame.getContentPane().add(label,BorderLayout.CENTER); frame.setLocationRelativeTo(null); frame.pack(); frame.setVisible(true); }else label.setIcon(new ImageIcon(image)); } public static BufferedImage getRandomFrame(){ BufferedImage img = new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB); for(int y = 0; y < 50; y ++){ for(int x = 0; x < 50; x ++){ int a = 255; int r = (int) (Math.random() * 256); int g = (int) (Math.random() * 256); int b = (int) (Math.random() * 256); int p = (a<<24) | (r<<16) | (g<<8) | b; img.setRGB(x, y, p); } } return img; } public static BufferedImage resize(BufferedImage img, int newW, int newH) { Image tmp = img.getScaledInstance(newW, newH, Image.SCALE_SMOOTH); BufferedImage dimg = new BufferedImage(newW, newH, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = dimg.createGraphics(); g2d.drawImage(tmp, 0, 0, null); g2d.dispose(); return dimg; } }