Hello,
I have some problems displaying a BufferedImage in a GUI.
The program I'm writing uses a set of rules to generate an integer array representing an image in RGBA. I have something like this:
Values[0] = 1st pixel / R component
Values[1] = 1st pixel / G component
Values[2] = 1st pixel / B component
Values[3] = 1st pixel / A component
Values[4] = 2nd pixel / R component
Values[5] = 2nd pixel / G component
...
I am then creating a BufferedImage like this:
this.image = new BufferedImage(this.width, this.height, BufferedImage.TYPE_INT_ARGB); this.image.setRGB(0, 0, this.width, this.height, Values, 0, this.width);
When verifying if that BufferedImage contains the right values, I found that it does.
But the problem is, I can't display it. I tried painting in on a JPanel or JLabel, creating an ImageIcon out of it... It is as if it was completely transparent although the alpha values are varying.
this is the crucial part of the code:
When i run this code, everytime the function step() is called, The program should display a new BufferedImage in the Jlabel 'view'.public void step(JLabel view) { BufferedImage image = this.displayGrid.computeGraphics(this.cellGrid); // Construction of the BufferedImage with random // values int[] results = image.getRGB(0, 0, this.width, this.height, null, 0, this.width); for(int i = 0; i < results.length; i++) System.out.println(results[i]); // to see the values contained in 'image' ImageIcon icon = new ImageIcon(image); view.setIcon(icon); // this doesn't seem to do anything although it should ! }
What I actually get is that everything seems to work fine but 'view' stays empty throughout the execution...
Any help is appreciated and sorry if I'm doing something dumb :^)
Thanks in advance