R
Rupert Woodman
Hi all,
I have an application which reads a JPG image and converts it to PNG format,
using the code shown below. This is the simplest illustration I can come up
with (i.e. it's not production code!).
The problem I have is that the initial JPG image is about 1 meg, the PNG
file is about 4.5 meg. Both have the same colour depth, so I'm wondering
why the size difference, and probably more importantly, how to decrease the
size of the resulting PNG.
Applications which I have used which write a PNG file generally give a
slider to say how much compression to apply, so I kind of thought there
would be something which would allow me (as a programmer) to decide how much
compression to use (resulting in longer compression times), but I can't see
anything.
Looking through the Java2D documentation, it kind of assumes you're pretty
au fait with image terminology, which I'm not!
Could anyone explain to me why the increase in size, and what I can do about
reducing the PNG file size (and what the drawbacks of doing so are)?
Many thanks.
My code:
public void convert()
{
String inputFilename="c:/temp/input.jpg";
String outputFilename="c:/temp/output.png";
BufferedImage bi;
try {
bi = ImageIO.read(new File(inputFilename));
ImageIO.write(bi, "png", new File(outputFilename));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
I have an application which reads a JPG image and converts it to PNG format,
using the code shown below. This is the simplest illustration I can come up
with (i.e. it's not production code!).
The problem I have is that the initial JPG image is about 1 meg, the PNG
file is about 4.5 meg. Both have the same colour depth, so I'm wondering
why the size difference, and probably more importantly, how to decrease the
size of the resulting PNG.
Applications which I have used which write a PNG file generally give a
slider to say how much compression to apply, so I kind of thought there
would be something which would allow me (as a programmer) to decide how much
compression to use (resulting in longer compression times), but I can't see
anything.
Looking through the Java2D documentation, it kind of assumes you're pretty
au fait with image terminology, which I'm not!
Could anyone explain to me why the increase in size, and what I can do about
reducing the PNG file size (and what the drawbacks of doing so are)?
Many thanks.
My code:
public void convert()
{
String inputFilename="c:/temp/input.jpg";
String outputFilename="c:/temp/output.png";
BufferedImage bi;
try {
bi = ImageIO.read(new File(inputFilename));
ImageIO.write(bi, "png", new File(outputFilename));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}