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?
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.
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.
createAsyncThunk accepts three parameters: a string action type value, a payloadCreator callback, and an options object.
I read images using ImageIO.
Image i = ImageIO.read(InputStream in);
The javadoc will offer more info as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With