Re: problem while regenerating jpg file from swing image.

From: Ann (Ann_at_nospam.invalid)
Date: 01/07/05


Date: Fri, 7 Jan 2005 01:10:05 -0600


"Roja" <damerlaroja@gmail.com> wrote in message
news:437e2c17.0501062141.5a3a7602@posting.google.com...
> Hi,
>
> I am trying to regenerate the jpg file with the image that is
> generated by java swings. But the x,y positions are not matching from
> swing generated image to jpg file generated.Any body worked on the
> similar problem please suggest.
>
> Thanks in advance.

This is what I use, works great.
HTH
Ann...................................................
I = (BufferedImage)createImage(width, height);
try
{
  File dir = new File(".");
  File fn = File.createTempFile("myImage", ".jpg", dir);
  String p = fn.getCanonicalPath();
  FileOutputStream fos = new FileOutputStream(p);
  JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(fos);
  JPEGEncodeParam par = encoder.getDefaultJPEGEncodeParam(I);
  par.setQuality(0.30F, true);
  encoder.setJPEGEncodeParam(par);
  encoder.encode(I);
  fos.flush();
  fos.close();
}
catch (FileNotFoundException e)
{
  System.out.println(e);
}
catch (IOException ioe)
{
  System.out.println(ioe);
}