BMP to JPEG Conversion

How do convert BMP file to JPEG format in java? Our application uses AWT and Swing classes. Thanks,Madan Shah
[151 byte] By [MadanShaha] at [2007-11-27 2:40:20]
# 1
look at ImageIO package
MaxxDmga at 2007-7-12 3:03:08 > top of Java-index,Java Essentials,Java Programming...
# 2

Example code using files.

File in = new File("bmp filespec");

File out = new File("jpg filespec");

BufferedImage bufi;

try

{

bufi = ImageIO.read(in);

ImageIO.write(bufi, "jpg", out);

}

catch (IOException ex)

{

ex.printStackTrace();

}

ChuckBinga at 2007-7-12 3:03:08 > top of Java-index,Java Essentials,Java Programming...
# 3
Thanks. Is Java ImageIO library part of standard java JRE? What version of JRE Image IO class was introduced?
MadanShaha at 2007-7-12 3:03:08 > top of Java-index,Java Essentials,Java Programming...
# 4
http://java.sun.com/javase/6/docs/api/javax/imageio/ImageIO.html
jawadhashmia at 2007-7-12 3:03:08 > top of Java-index,Java Essentials,Java Programming...
# 5

Thanks for the code. It works well when I run it in JRE 1.6 but fails in JRE1.4 with a NullPointerException. The problem is with this line:?br>

bufi = ImageIO.read(in);

I believe JDK1.4 does not support reading a bmp file format. Is this the problem? And if so, is there a Java work-around apart from migrating to JDK 1.5 or 1.6?

MadanShaha at 2007-7-12 3:03:08 > top of Java-index,Java Essentials,Java Programming...
# 6
ImageIO uses a service provider pattern for its ImageReaders and ImageWriters.You could look into this. Perhaps the Java Advanced Image I/O download includes readers and writers for BMP files.
DrLaszloJamfa at 2007-7-12 3:03:09 > top of Java-index,Java Essentials,Java Programming...
# 7
Here's a link: https://jai-imageio.dev.java.net/it looks like it includes BMP.
DrLaszloJamfa at 2007-7-12 3:03:09 > top of Java-index,Java Essentials,Java Programming...