BufferedImage什么时候用getGraphics什么时候又用createGraphics()

我知道一个是创建 Graphics2D对象,一个是获取一个 Graphics2D对象。

那两个有什么区别?

我看代码里都有

public void init(){

 int width=480,hight=720;  
 image = new BufferedImage(width,hight,BufferedImage.TYPE_INT_RGB);  
 //获取图形上下文 
 graphics = (Graphics2D)image.getGraphics();  

}

java Graphics2D 画图

(1):创建一个Graphics2D,可以画到BufferedImage中。

BufferedImage buf=new
BufferedImage(img.getWidth(this),img.getHeight(this),BufferedImage.TYPE_INT_ARGB);

创建一个临时Graphics2D对象。

Graphics tmpG=buf.createGraphics();

将图像画入临时缓冲中:

tmpG.drawImage(img,10,10,this);

JAVA---Graphics2D类


看起来都是初始化阶段使用的,之间也没什么区别麻

谢谢。

阅读 2.9k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题