problem while regenerating jpg file from swing image.

R

Roja

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.
 
A

Ann

Roja said:
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);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top