resizing working very long in method drawImage()
Hi! i found code for resizing of images .jpg, .gif, .png. And method that described below gave best quality but for some images it's work very long time ~30 second (method drawImage() do it so long), for others (not depended from size of image ~ 300ms - 3s). Code:
BufferedImage bufimg = ImageIO.read(new FileInputStream("E:/2.jpg"));
double k=(double)bufimg.getWidth()/(double)bufimg.getHeight();
int width=150;
int height=150;
int iw=bufimg.getWidth();
int ih=bufimg.getHeight();
Image image=null;
BufferedImage result=null;
if (iw>ih){
width=(int)Math.round(height*(
(double)bufimg.getWidth()/(double)bufimg.getHeight()));
image=bufimg.getScaledInstance(
width,height,Image.SCALE_AREA_AVERAGING);
result=new BufferedImage(width, height, BufferedImage.OPAQUE);
int x=(width/2)-75;
result=result.getSubimage(x,0,150,150);
}elseif (ih>iw){
height=(int)Math.round(width/(
(double)bufimg.getWidth()/(double)bufimg.getHeight()));
image=bufimg.getScaledInstance(
width,height,Image.SCALE_AREA_AVERAGING);
result=new BufferedImage(width, height, BufferedImage.OPAQUE);
int y=(height/2)-75;
result=result.getSubimage(0,y,150,150);
}
Graphics2D g = result.createGraphics();
g.drawImage(image, 0, 0,null);
g.dispose();
BufferedOutputStream out =new BufferedOutputStream(newFileOutputStream("E:/2_one.jpg"));
ImageIO.write(result,"jpg", out);
Please help, how to resolve this problem?

