下面程序是将一张图片修改成50*50的图片 ,可以通过修改 new_wi和new_he来调整
public byte[] imageChangeSize(byte[] data) throws IOException {
int orig_wi = 0 ;int orig_hi = 0 ;
int fin_w = 0 ;
int fin_h = 0 ;
int new_wi = 50;
int new_he = 50;
// byte[] data = getPicture(row, col);
InputStream is = new ByteArrayInputStream(data);
BufferedImage bufImg = ImageIO.read(is);
orig_wi = bufImg.getWidth();
orig_hi = bufImg.getHeight();
if(orig_wi < new_wi){
fin_w = orig_wi;
}else{
fin_w = new_wi;
}
if(orig_hi < new_he){
fin_h = orig_hi;
}else{
fin_h = new_he;
}
BufferedImage bf = new BufferedImage(new_wi,new_he,BufferedImage.TYPE_INT_RGB );
bf.getGraphics().drawImage(bufImg.getScaledInstance(fin_w, fin_h, Image.SCALE_SMOOTH),0,0,fin_w, fin_h,null);
ByteArrayOutputStream out = new ByteArrayOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(bf);
byte[] re = out.toByteArray();
return re;
}