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?

[2624 byte] By [Rygela] at [2007-11-26 15:55:42]
# 1
http://java.sun.com/products/java-media/2D/reference/faqs/index.html#Q_How_do_I_create_a_resized_copyDmitri
dmitri_trembovetskia at 2007-7-8 22:16:27 > top of Java-index,Security,Cryptography...