Jump to content
  • Advertisement
Sign in to follow this  
CodeMachine

[java] createImage + MemoryImageSource - getGraphics() ?

This topic is 4433 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
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
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!