簡體   English   中英

為什么VolatileImage.getGraphics()總是創建Graphics的新實例?

[英]Why VolatileImage.getGraphics() create always a new instance of Graphics?

我有以下代碼

 final Graphics2D g2d1 = (Graphics2D) volatileImg.getGraphics();
 final Graphics2D g2d2 = (Graphics2D) volatileImg.getGraphics();

為什么g2d1 != g2d2 ??

為什么volatileImg.getGraphics()在每個調用中創建一個新實例?

有什么辦法可以獲取始終相同的Graphics2D

謝謝 :)

在這里,我做了一些改進,以提高JComponent View的性能:1-使用VolatileImage代替BufferedImage並僅在寬度和高度時創建一個新實例。

volatileImg = component.getGraphicsConfiguration().createCompatibleVolatileImage(width, heigth, Transparency.BITMASK); // I used Transparency.BITMASK for more cpu rapidity

2-我在字段中保留了Graphics的引用以調用Graphics#dispose。

你怎么看 ?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM