Rendering image in java
<p>I'm trying to put a picture in java JFrame, but i want to modify every pixel, so i want to load it pixel by pixel. I'm stuck at part where pixels should be loaded to the screen but i see no effect. What did i miss?</p>

<p>I'm pretty sure it's something small but for some reason i cant see it.</p>

<p>Display.java</p>

<pre><code>public class Display extends Canvas  implements Runnable{


public static int WIDTH=1280;
public static int HEIGHT=800;
public static final String TITLE = "rainbow effect";

private Thread thread;
private boolean running = false;
private Screen screen;
private BufferedImage img;
private int pixels[];

public Display(){
    Dimension size = new Dimension(WIDTH,HEIGHT);
    setPreferredSize(size);
    setMinimumSize(size);
    setMaximumSize(size);
    screen = new Screen(WIDTH, HEIGHT);
    img = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
    pixels = ((DataBufferInt)img.getRaster().getDataBuffer()).getData();

}

@Override
public void run() {
    while(running){
        requestFocus();
        render();

    }   
}

public synchronized void start(){
    if(running) 
        return;
    running = true;
    thread = new Thread(this);
    thread.start();

    //System.out.println("working...");
}


public synchronized void stop(){
    if(!running)
        return;
    running = false;
    try{
        thread.join();
    } catch(Exception e){
        e.printStackTrace();
        System.exit(0);
    }
}   


private void render(){
    BufferStrategy bs = this.getBufferStrategy();
    if(bs == null)
    {
        createBufferStrategy(3);
        return;
    }
    screen.render();
    for(int i=0; i&lt;WIDTH*HEIGHT; i++)
    {
        pixels[i] = screen.pixels[i];
    }
//-------------------EDIT------------//
    Graphics g = bs.getDrawGraphics();
    g.drawImage(img, 0, 0, WIDTH, HEIGHT, null);
    g.dispose();
//--------------END OF EDIT-----------//
    bs.show();
}

    public static void main(String[] args){
        //BufferedImage cursor = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
        //Cursor blank = Toolkit.getDefaultToolkit().createCustomCursor(cursor, new Point(0,0), "blank");
        Display game = new Display();
        JFrame frame = new JFrame();
        frame.add(game);

        frame.setTitle(TITLE);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setResizable(false);
        frame.pack();
        //frame.getContentPane().setCursor(blank);
        frame.setVisible(true);

        System.out.println("running ...");

        game.start();


    }
}
</code></pre>

<p>Screem.java</p>

<pre><code>public class Screen extends Render {

private Render test;

public Screen(int width, int height) {
    super(width, height);
    Random random = new Random();
    //test = new Render(width, height);
    test = new Render(width, height);
    for(int i=0; i&lt;width*height; i++){
        test.pixels[i] = Image.img.pixels[i];
        }
}

public void render(){
    for(int i =0 ; i &lt;width*height;i++){
        pixels[i]=0;
    }

    test.draw(test, 0, 0);
}

}
</code></pre>

<p>Render.java</p>

<pre><code>public class Render {
public final int width, height;
public final int [] pixels;

public Render(int width, int height){
    this.width = width;
    this.height = height;
    pixels = new int[width * height];
}

public void draw(Render render, int xOffset, int yOffset){
    for(int y=0; y&lt;render.height; y++){
        int yPix = y+yOffset;
        if(yPix&lt;0 || yPix &gt;=height){
            continue;
        }
        for(int x=0; x &lt; render.width; x++){
            int xPix = x+xOffset;
            if(xPix &lt; 0 ||yPix &gt;=width){
                continue;
            }
            int alpha = render.pixels[x+y*render.width];
            if(alpha &gt;0)
            {
                pixels[xPix+yPix*width]=alpha;
            }
        }
    }
}

}
</code></pre>

<p>Image.java</p>

<pre><code> public class Image {
 public static Render img = loadBitmap("/images/sample2.jpg");

public static Render loadBitmap(String fileName){
    try{
        BufferedImage image = ImageIO.read(Image.class.getResource(fileName));
        int width = image.getWidth();
        int height = image.getHeight();
        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);

    }
}
}
</code></pre>