/Users/lyon/j4p/src/j2d/edge/gabor/BufferedImageCanvas.java

1    package j2d.edge.gabor; 
2     
3     
4    import graphics.NumImage; 
5     
6    import java.awt.*; 
7    import java.awt.image.BufferedImage; 
8     
9    class BufferedImageCanvas extends Canvas { 
10       private BufferedImage image; 
11    
12       public BufferedImageCanvas(BufferedImage img) { 
13           image = img; 
14           this.setSize(image.getWidth(this), image.getHeight(this)); 
15       } 
16    
17       public BufferedImageCanvas() { 
18           Image img = NumImage.getImage(); 
19           int w = img.getWidth(this); 
20           int h = img.getHeight(this); 
21           image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); 
22           setSize(image.getWidth(this), image.getHeight(this)); 
23           Graphics2D g2 = image.createGraphics(); 
24           g2.drawImage(img, 0, 0, this); 
25       } 
26    
27       public void drawImage() { 
28           this.repaint(); 
29       } 
30    
31       public Image getImage() { 
32           return image; 
33       } 
34    
35       public void setImage(BufferedImage img) { 
36           image = img; 
37       } 
38    
39       public void paint(Graphics graphics) { 
40           if (image != null) 
41               graphics.drawImage(image, 0, 0, this); 
42    
43       } 
44    
45    
46   } 
47