Use ImageIO
, it can read/write JPEG, PNG, GIF, and BMP out of the box.
ImageIO.write(ChartImage, "jpeg", out);
Usually the static write(...)
and read(...)
methods are enough, if you need to control compression or handle image meta data, check out the Java Image I/O API Guide.