Skip to main content
gamedev.net
🔒 Locked

[java] Loading bitmaps in an application...

Started by Kentaro 4 replies 500+ views
Original Post
Kentaro
Kentaro
I''d had some success with loading and displaying a JPG as a BufferedImage by using ImageIO.read(File), but the same method doesn''t work for BMP files. Instead, the program exits abnormally with a NullPointerException. How can I load BMP files in an application? Is using ImageIO a bad idea in the first place?
Over the centuries, mankind has tried many ways of combating the forces of evil...prayer,fasting, good works and so on. Up until Doom, no one seemed to have thought about thedouble-barrel shotgun. Eat leaden death, demon... -- Terry Pratchett
Petr Stedry
Petr Stedry
Hi,

IMHO the javax.imageio library is an excellent addition to the java core libraries and you should use it wherever you need to R/W images.

To address the problem of bitmaps ... don''t use them!
Why don''t you convert bitmaps using some freeware program to PNG for example and use imageio to load those PNG files then ?

In the default instalation, there is no decoder for BMP. So that''s the source of the NullPointerException. To find out what formats are supported, call either getReaderFormatNames() or getWriterFormatNames() and you will know.

have a nice day ...
Petr Stedry
Kentaro
Kentaro
I have Adobe Photoshop, which seems to convert between whole lots of different formats. The project I''m working on isn''t too graphics intensive; it''s a tetris clone application, as opposed to an applet. Thanks for the tip about finding out which image formats are readable...

Are the readable image types VM specific?

This isn''''t life in the fast lane, it''''s life in the oncoming traffic.
-- Terry Pratchett
Over the centuries, mankind has tried many ways of combating the forces of evil...prayer,fasting, good works and so on. Up until Doom, no one seemed to have thought about thedouble-barrel shotgun. Eat leaden death, demon... -- Terry Pratchett
Petr Stedry
Petr Stedry
Hi,
IMHO the image types will be the same in every OS. And I guess you found that only JPEGs and PNGs are valid options for you.

And I think also, that it is possible to add other image readers/writers by yourself. What else would the rest of the imageIO API be for ?
If you want to learn, do so, if not, just use what is provided (PNGs were Ok for me and I didn''t have time to investigate further on writing custom image r/w plugins for imageio).

have fun

Petr Stedry
Petr Stedry
CaptainJester
CaptainJester
Don''t forget GIFs. Java can also natively load GIFs.



Make it work, then
make it fast.

"I’m happy to share what I can, because I’m in it for the love of programming. The Ferraris are just gravy, honest!" --John Carmack: Forward to Graphics Programming Black Book
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
Petr Stedry
Petr Stedry
Hi,

Although java (using java.applet.Applet.getImage(URL) or java.awt.Toolkit.getImage(URL/filename)) can load GIF and other types of images, I am not sure about ImageIO has this capability (GIF r/w) by default. The last time I checked it could r/w only JPEGs and PNGs.

But things could have changed ...

have fun

P.S.: The PNG format is an advanced form of the GIF (better color depth), so it should IMO be used instead of GIF, which have the 256 colors limitation.

Petr Stedry

[edited by - Petr Stedry on December 9, 2002 7:40:55 AM]
Petr Stedry

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.