Can someone give me an example of how to import a saved image into Java? I've looked all over the internet and need a quick and easy way to do it. I already know how to draw it (with g.drawImage).
Thanks!
Printable View
Can someone give me an example of how to import a saved image into Java? I've looked all over the internet and need a quick and easy way to do it. I already know how to draw it (with g.drawImage).
Thanks!
Read the API for Image and click the "Use" link at the top of the page. Go through the sections for methods that return Image.
If you don't find exactly what you want, you may need to consider whether a particular Image subclass serves the purpose. Go through any subclasses of Image and their subclasses and check out the "Use" of each, till you find a method that returns an Image that serves your purpose.
Hint: since you want to load a saved image, you will need to focus on methods that take a File or a URL/URI (or a String representation of any of those) as a parameter.
db
I use the ImageIO class to create BufferedImages - these work well for general java2d stuff! You can also save images with ImageIO!
Same here; but that class isn't documented anywhere nor is it part of a public API donated to us poor plebeians; I think it has something to do with the days when animated .gif files were patented; only the Sun gods were allowed to ingfringe that pattern but us ignorant sods still have to fiddle diddle with Timers and image redraws and all that crappy stuff ;-)
kind regards,
Jos