Java-ImageObserver,BufferedImage,Graphics2D,Graphics

来源:互联网 发布:touch.js官网 编辑:程序博客网 时间:2024/04/29 04:34

API:
ImageObserver : http://www.apihome.cn/api/java/ImageObserver.html
BufferedImage:http://www.apihome.cn/api/java/BufferedImage.html
Graphics2D:http://www.apihome.cn/api/java/Graphics2D.html
Graphics:http://www.apihome.cn/api/java/Graphics.html

ImageObserver是一个接口,ImageObserver就是Image的观察者,它时刻关注Image是否可用。
public abstract int getHeight(ImageObserver observer);

class MyPanel extends JPanel implements MouseListener, ImageObserver {

   BufferedImage bi;   private static final long serialVersionUID = 1L;   public MyPanel() {       this.addMouseListener(this);       bi = new BufferedImage(600, 400, 1);   }   public void paint(Graphics graphics) {       super.paint(graphics);       Graphics g2d = (Graphics2D) graphics;       g2d.drawImage(bi, 100, 100, this);   }

}

BufferedImage:
1. 在paint中new BufferedImage;
2. Graphics2D=bufferedimage.createGraphics();
3. Graphics2D.draw();
4. Graphics.drawImage().
public abstract void draw(Shape s)

使用当前 Graphics2D 上下文的设置勾画 Shape 的轮廓。应用的呈现属性包括 Clip、Transform、Paint、Composite 和 Stroke 属性。

Graphics2D,Graphics
Graphics2D提供对几何形状、坐标转换、颜色管理和文本布局更为复杂的控制;
Graphics 类是所有图形上下文的抽象基类,允许应用程序在组件(已经在各种设备上实现)以及闭屏图像上进行绘制
详细设计可以查阅:http://blog.csdn.net/cl18652469346/article/details/53117023

1 0
原创粉丝点击