java - 试图将图像添加到 JFrame
问题描述
您好,我正在尝试将桌面上的图像添加到我创建的 JFrame 中我的图像,但它在我的 drawImage 组件中导致错误,它要求一个图像观察者,我不知道它是什么,如果我自动填充一些我的图像没有出现在我的 JFrame 上。如果你们中的一个人可以查看我的代码或回答图像观察者的工作,我将不胜感激
public class Window2 extends JPanel {
// Image Import
ImageIcon i = new ImageIcon("C: / Class Pokemon Game/ src / GameTitle (1).psd");
Image title = i.getImage();
public void paintComponent(Graphics g)
{
super.paintComponent(g);
this.setBackground(Color.BLACK);
g.setColor(Color.RED);
g.fillRect(0, 40, 5000, 20);
g.**drawImage**(title, 500, 500);
}
}
错误是添加参数以匹配'drawImage(Image,int,int,ImageObserver)'
解决方案
You can skip using an ImageObserver by putting it as null for example (Using Graphics2D)
g2.drawImage(Image texture, x, y, width, height, null);
推荐阅读
- visual-studio - m_safeCertContext 是一个无效句柄 - 为什么我的代码在生产环境中有效,但在开发环境中无效?
- google-sheets - 如何让单元格中的值改变一天中的时间和日期的条件?
- ios - node_modules/react-native-vector-icons/lib/create-icon-set.js: #
无法克隆 - perl - Perl中变量名中的单引号?
- keras - Keras Sequence ImageDatagenerator 在一个数组和两个数组中返回 X,y 时的性能差异
- javascript - 如何将变量传递给箭头函数?
- javascript - NFoxygenD3.js:4 未捕获的进度事件
- prolog - 在序言中找到与团队相同的球员
- excel - 尝试在自动筛选后选择 DataBodyRange 中的可见单元格时,“工作表类的选择方法失败”
- macos - 在 Mac M1 上的特定位置安装 chromedriver?