Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you read an image in Java when Toolkit.getDefaultToolkit() throws an AWTError?

Tags:

java

image

awt

I am reading image files in Java using

java.awt.Image img = Toolkit.getDefaultToolkit().createImage(filePath);

On some systems this doesn't work, it instead throws an AWTError complaining about sun/awt/motif/MToolkit.

How else can you create a java.awt.Image object from an image file?

like image 361
Chris Carruthers Avatar asked Sep 23 '08 08:09

Chris Carruthers


People also ask

What is toolkit getDefaultToolkit ()?

public static synchronized Toolkit getDefaultToolkit () The getDefaultToolkit() method returns the system's default Toolkit object. The default Toolkit is identified by the System property awt. toolkit, which defaults to an instance of the sun.

What is toolkit class in Java?

This class is the abstract superclass of all actual implementations of the Abstract Window Toolkit. Subclasses of the Toolkit class are used to bind the various components to particular native toolkit implementations. Many GUI events may be delivered to user asynchronously, if the opposite is not specified explicitly.

How many parameters does the tool kit accept?

createAsyncThunk accepts three parameters: a string action type value, a payloadCreator callback, and an options object.


1 Answers

I read images using ImageIO.

Image i = ImageIO.read(InputStream in);

The javadoc will offer more info as well.

like image 185
jjnguy Avatar answered Sep 20 '22 23:09

jjnguy