Error Reading Image

Posted by javawarrior on Stack Overflow See other posts from Stack Overflow or by javawarrior
Published on 2012-11-24T11:19:36Z Indexed on 2012/11/30 5:04 UTC
Read the original article Hit count: 213

Filed under:
|
|

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: The Image I use

© Stack Overflow or respective owner

Related posts about java

Related posts about image