package elte.java2_utikalauz5.java2d; import java.awt.*; import java.awt.image.*; import java.awt.color.*; import java.awt.event.*; /** peldaprogram egy BufferedImage kep eloallitasara, felhasznalva a megfelelo DataBuffer, SampleModel, Raster, ColorModel osztalyokat. @link.forrásfájl {@docRoot}/../data/java2d/src KepEloallitas.java @link.letöltés {@docRoot}/../data/java2d KepEloallitas.jar @since Java 2 Útikalauz programozóknak */ class KepEloallitas extends Canvas { /** Verziószám */ private final static long serialVersionUID = 15L; BufferedImage kep; public void kepKeszites () { int [] pixelek = new int[100 * 100]; WritableRaster raster = Raster.createWritableRaster( new PixelInterleavedSampleModel (DataBuffer.TYPE_BYTE, 100, 100, 1, 100, new int[] {0}), new DataBufferByte (100 * 100), null); for (int i = 0; i < 100; i++) for (int j = 0; j < 100; j++) pixelek[i * 100 + j] = i; raster.setPixels (0, 0, 100, 100, pixelek); ColorSpace szurkeSzinmodell = ColorSpace.getInstance (ColorSpace.CS_GRAY); ColorModel ccm = new ComponentColorModel (szurkeSzinmodell, new int[] {1}, false, false, 1, DataBuffer.TYPE_BYTE); kep = new BufferedImage (ccm, raster, false, null); } public void paint (Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.drawImage (kep, 0, 0, this); } public static void main (String[] args) { Frame f = new Frame (); KepEloallitas k = new KepEloallitas (); k.kepKeszites (); f.add (k); f.addWindowListener ( new WindowAdapter () { public void windowClosing (WindowEvent e) { System.exit (0); } } ); f.setSize (150, 150); f.setVisible (true); } }