• Advertisement
Sign in to follow this  

[java] createImage + MemoryImageSource - getGraphics() ?

This topic is 4166 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().createCompatableImage(width, height);

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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);
}
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement