1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
import java.awt.image.*;
import javax.imageio.*;
import java.io.*;
import java.awt.*;
import javax.swing.*;
public class image {
private static class FrameShower implements Runnable {
final Frame frame;
public FrameShower(Frame frame) {
this.frame = frame;
}
public void run() {
frame.show();
}
}
public static void main(String args[]) throws IOException {
File file = new File("005743.jpg");
BufferedImage input = ImageIO.read(file);
System.out.println(input);
// Convert
Kernel sharpKernel = new Kernel(3, 3, new float[] { 0.0f, -1.0f, 0.0f, -1.0f, 5.0f, -1.0f, 0.0f, -1.0f, 0.0f });
ConvolveOp convolveOp = new ConvolveOp(sharpKernel, ConvolveOp.EDGE_NO_OP, null);
int width = input.getWidth();
int height = input.getHeight();
BufferedImage output = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
convolveOp.filter(input, output);
// Make screen
Icon icon = new ImageIcon(output);
JLabel label = new JLabel(icon);
JFrame frame = new JFrame("Sharp Image");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(label, BorderLayout.CENTER);
frame.pack();
// Show
Runnable runner = new FrameShower(frame);
EventQueue.invokeLater(runner);
}
} |
Partager