[java] createImage + MemoryImageSource - getGraphics() ?
Hi
I have a class, A. This class doesn't inherit another class.
When I create instances of this class, I want to create an image within
the constructor.
I then use this method:
Image img = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(w, h, pixels, 0, w));
Is there a way to get a Graphics object from the image returned from createImage above?
If I call "img.getGraphics()" I get the error:
"getGraphics() not valid for images created with createImage(producer)"
Kind Regards
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().createCompatableImage(width, height);
Hi Captain
That method is abstract, it doesn't work. :|
Is there an option where I still can use my raw-pixel array to fill the bitmap?
And have the ability to "getGraphics()"?
Kind Regards
That method is abstract, it doesn't work. :|
Is there an option where I still can use my raw-pixel array to fill the bitmap?
And have the ability to "getGraphics()"?
Kind Regards
You are using it wrong. Here is code that works.
import java.awt.GraphicsEnvironment;import java.awt.image.BufferedImage;public class Test { public static void main(String[] args) { BufferedImage im = GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration().createCompatibleImage(400, 400); System.out.println(im); }}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement