Hi,
When I run the program ImageUtil1.java using JRE 1.6 ,I am getting a thumb image with good quality.
But If I change the jre version to 1.5 then the quality of the thumb image is not good.
code :
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.imageio.ImageIO;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
public class ImageUtil1 {
public static void main (String [] args) {
try {
File myDicomFile = new File("D:\\thumbImages\\i1.jpg");
FileInputStream fin = new FileInputStream(myDicomFile);
byte [] imageBytes = new byte[ (int) myDicomFile.length () ];
System.out.println("ImageUtil1.main() "+imageBytes.length);
fin.read (imageBytes);
saveThumbImage(imageBytes, "QC_i1");
} catch (Exception e) {
e.printStackTrace ();
}
}
public static void saveThumbImage(byte[] image,String fileName){
try{
Image thumb;
ByteArrayInputStream bis = new ByteArrayInputStream(image);
thumb = ImageIO.read(bis);
int thumbWidth = Integer.parseInt("128");
int thumbHeight = Integer.parseInt("128");
int width = thumb.getWidth(null);
int height = thumb.getHeight(null);
BufferedImage bi = new BufferedImage(thumbWidth,thumbHeight,BufferedImage.TYPE_INT_RGB);
Graphics2D g = bi.createGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BICUBIC);
g.drawImage(thumb, 0, 0,thumbWidth,thumbHeight, null);
ByteArrayOutputStream out1 = new ByteArrayOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out1);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
param.setQuality((float)(75/100.0), true);
encoder.encode(bi, param);
byte[] buf = out1.toByteArray();
String thumbImagePath = "D:\\thumbImages\\";
FileOutputStream os = new FileOutputStream(new File(thumbImagePath+fileName+".jpg"));
os.write(buf);
}
catch(IOException ioException){
ioException.printStackTrace();
}
}
}
I need it to run it on jre1.5
Please help me
Thanks in advance..
-Phanikanth