我正在尝试制作一款游戏,而我正在使用我发现的拼图(png)。我希望能够将图像分成几部分并将它们放在jframe中的特定位置以显示运动。但首先我将如何开始导入图像。我所有的尝试都失败了,导入时图像变成了文本文件。请帮助解决这个问题,我将如何切割和排列瓷砖?
Exception in thread "main" java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read(Unknown Source)
at World.Display.<init>(Display.java:15)
at Main
。主要(Main.java:15)
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
World.Display l = new World.Display();
}
}
package World;
import java.awt.GridLayout;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Display {
public Display() throws IOException{
BufferedImage img=ImageIO.read(getClass().getResource("assets/tilesetbackground.png/"));
ImageIcon icon=new ImageIcon(img);
JFrame frame=new JFrame();
frame.setTitle("Another RPG Version: "+Config.Global.Version);
frame.setLayout(new GridLayout(1024,768));
frame.setSize(1024,768);
JLabel lbl=new JLabel();
lbl.setIcon(icon);
frame.add(lbl);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}