Re: BufferedImage



Martijn Mulder wrote:
I try to load an image into a BufferdImage instance in the constructor
of my class. It does not work.

Wrong, loading works. But then you do the wrong thing with it.

 //data member graphics2d
 java.awt.Graphics2D graphics2d=displayimage.createGraphics();

This is the Graphics context of the Image itself.

graphics2d.drawImage(image,0,0,this);

Here you draw the image on itself by using its own Graphics context.

Please note, however, that changing to the "right" Graphics context will not work. There is no right Graphics context the moment you try to paint. The idea of painting ("pushing" graphics onto a component) outside of the paint[Component]() method is basically flawed.

Q3.4 of the comp.lang.java.gui FAQ basically applies to your problem. The TCS article about painting in AWT and Swing is also a good read.

/Thomas

--
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
.



Relevant Pages

  • Re: Double-Buffering Without drawImage?
    ... the graphics context that was the off-screen ... If you're not limited to AWT, and can use Swing, I think you get ... the double buffering details for you. ... from main memory, or from graphics memory, or page flipping, or ...
    (comp.lang.java.programmer)
  • Re: Porting Win32 GUI to Java 2D
    ... This really breaks my heart - as I had vowed never to go back to Windoze - plus it means having to maintain two code branches - but if the truth be told. ... SWING is not really ready for prime time. ... Whic Java functions are you using as equivalent to the Windows GDI functions like the ones listed above?. ... Most of what you seem to be after is part of the graphics context. ...
    (comp.lang.java.gui)