I need to create an image using
Image createImage(byte[] imagedata)
(NOT createImage(ImageProducer producer))
My code is
import java.awt.*;
import java.awt.image.*;
class MyCreateImage extends Frame{
Image img;
public static void main (String args[]) {
new MyCreateImage("Create Image");
}
public MyCreateImage(String s) {
super(s);
setSize(600, 500);
setVisible(true);
byte pixels[] = {100, 60, 100, 10, 50};
img = Toolkit. getDefaultToolkit(). createImage(pixels)
System.out.println("w = " + img.getWidth(this));
System.out.println("h = " + img.getHeight(this));
}
public void paint (Graphics g) {
g.drawImage(img, 100, 100, this);
} }
Why I get
--> w = -1
--> h = -1
I would appreciate any help! Thanks in advance.
Tags: