package elte.java2_utikalauz5.java2d; import java.awt.*; import java.awt.image.*; import java.awt.event.*; /** peldaprogram a konvolucios muveletek megvalositasara. @link.forrásfájl {@docRoot}/../data/java2d/src Elesites.java @link.letöltés {@docRoot}/../data/java2d Elesites.jar @since Java 2 Útikalauz programozóknak */ class Elesites extends Canvas { /** Verziószám */ private final static long serialVersionUID = 15L; Image kep; BufferedImage eredetiKep, ujKep; public void kepBetoltes () { setBackground (Color.white); kep = getToolkit ().getImage (getClass().getClassLoader().getResource("kep.jpg")); try { MediaTracker tracker = new MediaTracker (this); tracker.addImage (kep, 0); tracker.waitForID (0); } catch (Exception e) { } } public void paint (Graphics g) { Graphics2D g2 = (Graphics2D) g; // a betoltott kepbol egy BufferedImage kepet keszitunk eredetiKep = new BufferedImage (kep.getWidth (this), kep.getHeight (this), BufferedImage.TYPE_INT_RGB); eredetiKep.createGraphics ().drawImage (kep, 0, 0, null); ujKep = new BufferedImage (kep.getWidth (this), kep.getHeight (this), BufferedImage.TYPE_INT_RGB); float[] sulyok = {-1.0f, -1.0f, -1.0f, -1.0f, 9.0f, -1.0f, -1.0f, -1.0f, -1.0f }; ConvolveOp elesites = new ConvolveOp (new Kernel (3, 3, sulyok)); elesites.filter (eredetiKep, ujKep); // kirajzoljuk az eredeti es az uj kepet g2.drawImage (eredetiKep, 20, 20, this); g2.drawImage (ujKep, 20, 220, null); } public static void main (String[] args) { Frame f = new Frame (); Elesites e = new Elesites (); e.kepBetoltes (); f.add (e); f.addWindowListener ( new WindowAdapter () { public void windowClosing (WindowEvent e) { System.exit (0); } } ); f.setSize (300, 450); f.setVisible (true); } }