Can you explain in more detail what exactly you want to do?
Saving an image in a file is very easy with the ImageIO API. It supports a number of different formats (the API documentation explains which ones). If you just want to save an image in for example JPG format, without worrying about the details, it's just one line of code:
If you want to be able to set parameters, for example the compression quality, then you'll have to look a little bit deeper into the ImageIO API. Here is an example that shows how to set the compression quality for a JPEG image:
Compression quality is unique to JPEG; note that while it does reduce the image size, it also reduces image quality. For all other image formats, use a value of 0.0 to indicate that you want high compression, just like the javadocs say. Also try setting the compression type before setting the compression quality; that's also mentioned in the javadocs.
Keep in mind that one major reason for image filetypes in general is their compression -- most of them are already compressed, and if there were an easy way to compress them further, the designers of that file format would already have used it.
Compression algorithms tend to take streams of bytes and find ways to represent the same information without repeating bytes, patterns, etc.; the GIF and PNG and other graphic formats have already done that, so they don't have many of the patterns other compression algorithms look for.