Image -> Jpg (koriscenjem com.sun.image.codec.jpeg paketa, JDK 1.2+)
Code:
public void saveImageToFile(Image img, String fileName) throws IOException {
BufferedImage bimg = null;
int w = img.getWidth(null);
int h = img.getHeight(null);
int [] pixels = new int[w * h];
PixelGrabber pg = new PixelGrabber(img,0,0,w,h,pixels,0,w);
try {
pg.grabPixels();
} catch(InterruptedException ie) {
ie.printStackTrace();
}
bimg = new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);
bimg.setRGB(0,0,w,h,pixels,0,w);
FileOutputStream fos = new FileOutputStream(fileName);
JPEGImageEncoder jpeg = JPEGCodec.createJPEGEncoder(fos);
jpeg.encode(bimg);
fos.close();
}