当我尝试使用打开一个简单的 smile.png 图像时
package com.java3d.java3d.graphics;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
public class Texture {
public static Render floor = loadBitMap("smile.png");
public Texture(){}
public static Render loadBitMap(String fileName) {
try {
BufferedImage image = ImageIO.read(Thread.currentThread().getContextClassLoader().getResource(fileName));
System.out.print(image==null);
int width = image.getWidth();
System.out.println(width);
int height = image.getHeight();
System.out.println(height);
System.out.println(image.getRGB(4, 4));
Render result = new Render(width, height);
image.getRGB(0, 0, width, height, result.pixels, 0, width);
return result;
} catch (Exception e) {
System.out.println("CRASH!");
throw new RuntimeException(e);
}
}
}
它将每个像素返回为 -1;什么可能导致这个问题?这是图像: