java - Java 中的drawImage() "null"

标签 java graphics drawimage

我的意思是drawImage()方法对我不起作用。人们说要做就做

g.drawImage(image, 0, 0, null);

但是eclipse实际上否认了这一点。它说:

The method drawImage(Image, int, int, ImageObserver) in the type Graphics is not applicable for the arguments (Image, int, int, null)

这实际上让我很困惑,我读过其他人的一些答案,他们总是说将其设置为空。 我尝试运行它,它给了我这个:

Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem: 
The method drawImage(Image, int, int, ImageObserver) in the type Graphics is not applicable for the arguments (Image, int, int, null)

at me.danielshe.graphics.DrawComponent.paintComponent(DrawComponent.java:29)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager$4.run(Unknown Source)
at javax.swing.RepaintManager$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.access$1200(Unknown Source)
at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

任何人都可以帮助我,或者这是一种放置某些内容而不是“null”的方法?我尝试将“this”放入其中,甚至实现 ImageObserver。但它们都不起作用。

谢谢。

最佳答案

您需要一个实现 ImageObserver 接口(interface)的对象。通常情况下 这将是与图形对象关联的组件。

关于java - Java 中的drawImage() "null",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49467082/

相关文章:

java - 如何获取 blogpostId firestore?

java - View.getId() 有效,而 button.getId() 无效

java - 在 JPanel 中强制调用 getPreferredSize()

java - 有什么方法可以调整 Java 游戏上的组件大小吗?

javascript - Uncaught Error : INDEX_SIZE_ERR

java - 在 Apache Karaf 3.0(OSGI 环境)中的 Atmosphere 上运行 Apache CXF

java - 计算数组中的元素个数

algorithm - 模拟自然铅笔需要画线算法

html - 用 Canvas 缩小大图像。平滑

javascript - 无法绘制大于 250px 正方形的图像