【发布时间】:2014-10-30 18:55:00
【问题描述】:
我的 JFrame 中有两个图像。第一个是原始图像,我希望第二个图像模糊。我有两个图像都反映在框架中,但第二个没有模糊。我怎样才能更好地编写这个程序来反映模糊的图像?
public static void main(String[] args) throws IOException {
String path = "src/logo.jpg";
File file = new File(path);
BufferedImage image = ImageIO.read(file);
JLabel label = new JLabel(new ImageIcon(image));
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(label);
f.pack();
f.setLocation(0,200);
f.setVisible(true);
String path2 = "src/logo.jpg";
File file2 = new File(path2);
BufferedImage image2 = ImageIO.read(file2);
JLabel label2 = new JLabel(new ImageIcon(image2));
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(label2);
f.pack();
f.setLocation(200,200);
f.setVisible(true);
float[] matrix = new float[400];
for (int i = 0; i < 400; i++)
matrix[i] = 1.0f/400.0f;
BufferedImageOp op = new ConvolveOp( new Kernel(20, 20, matrix), ConvolveOp.EDGE_NO_OP, null );
image2 = op.filter(image, null);
}}
我的第二张图片的位置也关闭了,甚至没有第一张图片。我的 setLocation 应该将两个图像并排放置,中间留有空格。
【问题讨论】:
标签: java jframe bufferedimage blur convolution