See documentation about createGraphics() in Graphics. I think your problem
is related to this method. In some circumstances the createGraphics()
returns a null value witch may likely happend when you try to create a
Graphics object outside a paint(), update(), paintComponent() or a method
related of drawing something on a component.
Jerome
-----Original Message-----
From: Roman Novikov [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, April 10, 2001 9:50
To: [EMAIL PROTECTED]
Subject: [JAVA2D] BufferedImage
Hello!
I'm a novice in Java, so my problem is drawing a BufferedImage.
Here is my code:
----------------------------------------------------------------------
import java.awt.*;
import javax.swing.*;
import java.awt.image.*;
import java.awt.event.*;
public class ImageTest extends JFrame {
int width;
int height;
BufferedImage bi;
Graphics2D big;
public void ImageTest() {
Image img =
Toolkit.getDefaultToolkit().getImage("images/boat.gif");
width = img.getWidth(this);
height = img.getHeight(this);
bi = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
big = bi.createGraphics();
big.drawImage(img, 0, 0, this);
}
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.drawImage(bi, 0, 0, this);
}
public static void main(String s[]) {
JFrame f = new ImageTest();
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
f.setTitle("ImageTest");
f.getContentPane();
f.pack();
f.setSize(new Dimension(300, 300));
f.show();
}
}
----------------------------------------------------------------------
I get a NullPointerException. Where is my problem?
Sincerely, 10.04.01
lloyd
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".