摘要:Java - ScaleImae and Base64 encode
private static final int IMG_SCALE = 512;
private static final int IMG_QUALITY = 75;
public String getScaleImage(Bitmap src01) {
String fs = null;
double scale ;
if(src01.getWidth() < src01.getHeight()){
scale = (double) src01.getWidth() / IMG_SCALE;
}else{
scale = (double) src01.getHeight() / IMG_SCALE;
}
int width = (int) ((double) src01.getWidth() / scale);
int height = (int) ((double) src01.getHeight() / scale);
Bitmap src02 = null;
src02 = null;
src02 = Bitmap.createScaledBitmap(src01, width, height, false);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
src02.compress(Bitmap.CompressFormat.JPEG, IMG_QUALITY, baos);
byte[] bmByteArary = baos.toByteArray();
String encoded = Base64.encode(bmByteArary);
fs = encoded;
return fs;
}