Error Reading Image
- by javawarrior
When I tried to open a simple smile.png image using
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);
}
}
}
it returns every pixel as -1; what could be causing this problem?
Here is the image: