Hi everyone,
I am trying to export a jcomponent as an image. The program all works but seriously the the quality of the saved image is really disgusting.
The words seems to be blurred. I think i have to use rendereing hints but i am not sure how there work or which hint to use for my situation.

Here is the code i use to convert a jcomponent to an image file

public void exporttableasjpeg(JComponent Component)
{
String k;


FileChooser1.setDialogType(JFileChooser.SAVE_DIALOG);
FileChooser1.setDialogTitle("Select Export File");


if(FileChooser1.showDialog(fr1, "Export") != JFileChooser.APPROVE_OPTION)
{
return;
}


File f = FileChooser1.getSelectedFile();
k = (f.toString() + ".JPG");
Dimension Size4 = Component.getSize();
BufferedImage Image1= new BufferedImage(Size4.width, Size4.height, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = Image1.createGraphics();
//I need someone to suggest a good hint to use for this situation


g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BICUBIC);
Component.paint(g2);


try
{
OutputStream out = new FileOutputStream(k);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(Image1);
out.close();
}


catch (Exception e)
{
Label1.setText("An error exporting the table as an image has occurred");
}


}

Basically i need someone to tell me if i am using the rendering hint in the right way and also to recommend an appropriate hint for my situation

Thank You

Yours Sincerely

Richard West

I've no experience with Java2D but I know something of JPEG :)

JPEG uses lossy compression which can lead to poor results if you get the image compressed too much.
Try finding a command to set the compression ratio and select the lowest compression (largest file) it supports. That should improve image quality.

If it doesn't, try to save to another file format and check if that does look good. If it does your encoder class may have a problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.