日期:2014-05-20 浏览次数:20737 次
/**
*
* @param srcImg 待处理图像
* @param width 缩小后的长度
* @param height 缩小后的宽度
* @return
*/
public BufferedImage SuoImg(BufferedImage srcImg,int width,int height){
BufferedImage targetImg=null;
double Sx=(double)width/srcImg.getWidth();
double Sy=(double)height/srcImg.getHeight();
int type=srcImg.getType();
if(type==0){
ColorModel cm=srcImg.getColorModel();
WritableRaster raster=cm.createCompatibleWritableRaster(width,height);
boolean alpha=cm.isAlphaPremultiplied();
targetImg=new BufferedImage(cm, raster, alpha,null);
}else{
targetImg=new BufferedImage(width, height, type);
}
Graphics2D g2=targetImg.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
g2.drawRenderedImage(srcImg,AffineTransform.getScaleInstance(Sx, Sy));
g2.dispose();
return targetImg;
}