Java Graphics2D.getDeviceConfiguration()的奇怪行为
这是我的程序草图,用于说明问题:Java Graphics2D.getDeviceConfiguration()的奇怪行为,java,Java,这是我的程序草图,用于说明问题: view = getGraphicsConfiguration().createCompatibleImage(100, 100); // creating a BufferedImage with size 100x100 Rectangle r = view.createGraphics().getDeviceConfiguration().getBounds(); // this correctly returns a rectangle of 10
view = getGraphicsConfiguration().createCompatibleImage(100, 100);
// creating a BufferedImage with size 100x100
Rectangle r = view.createGraphics().getDeviceConfiguration().getBounds();
// this correctly returns a rectangle of 100x100, as in my understanding the device
// is the BufferedImage and its size is 100x100
/* Later a new object is created, where 'view' again is assigned, so it is a different instance variable (even if it were the same object, I would not understand the behavior). */
view = getGraphicsConfiguration().createCompatibleImage(200, 200);
// creating a BufferedImage with size 200x200
Rectangle r = view.createGraphics().getDeviceConfiguration().getBounds();
// now this again returns a rectangle of 100x100, though I would expect it to return
// 200x200 (!?), for some reason the system seems to remember the old settings?
我检查了上面对getDeviceConfiguration的两次调用返回的GraphicsConfiguration。它是同一个物体
谢谢你的评论 view.getWidth和view.getHeight返回什么?什么是getGraphicsConfiguration?getWidth和getHeight返回正确的值,我做了一个简单的测试并验证了结果,我不确定我是否担心,当我这样做时,总是以这种方式创建图像,并依赖于getWidth和getHeight值……但这只是megeGraphicsConfiguration返回X11GraphicsConfig[dev=X11GraphicsDevice[screen=0],vis=0x21]