public static BufferedImage resizeImage(BufferedImage image, int width, int height) {
float w = new Float(width) ;
float h = new Float(height) ;
if ( w <= 0 && h <= 0 ) {
w = image.getWidth();
h = image.getHeight();
} else if ( w <= 0 ) {
w = image.getWidth() * ( h / image.getHeight() );
} else if ( h <= 0 ) {
h = image.getHeight() * ( w / image.getWidth() );
}
int wi = (int) w;
int he = (int) h;
BufferedImage resizedImage = new BufferedImage(wi,he,BufferedImage.TYPE_INT_RGB);
resizedImage.getGraphics().drawImage(
image.getScaledInstance(wi,he,Image.SCALE_AREA_AVERAGING),
0,0,wi,he,null
);
return resizedImage;
}
댓글 없음:
댓글 쓰기