int bw = bitmap.getWidth();
int bh = bitmap.getHeight();
float radio = (outHeight / (float) outWidth);
int tw = (int) (bh / radio);
int th = (int) (bw * radio);
int sw, sh, ow, oh;
if (tw <= bw) {
sw = tw;
sh = (int) (tw * radio);
oh = 0;
ow = (bw - sw) / 2;
} else {
sh = th;
sw = (int) (th / radio);
ow = 0;
oh = (bh - sh) / 2;
}
Matrix m = new Matrix();
m.preScale(outWidth / (float) sw, outHeight / (float) sh);
bitmap = Bitmap.createBitmap(bitmap, ow, oh, sw, sh, m, false);