Mã bên dưới đổi kích thước bitmap và giữ tỷ lệ khung hình. Tôi đã tự hỏi nếu có một cách hiệu quả hơn thay đổi kích thước, bởi vì tôi có ý tưởng rằng tôi đang viết mã đã có sẵn trong API Android.Thay đổi kích thước bitmap
private Bitmap resizeImage(Bitmap bitmap, int newSize){
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int newWidth = 0;
int newHeight = 0;
if(width > height){
newWidth = newSize;
newHeight = (newSize * height)/width;
} else if(width < height){
newHeight = newSize;
newWidth = (newSize * width)/height;
} else if (width == height){
newHeight = newSize;
newWidth = newSize;
}
float scaleWidth = ((float) newWidth)/width;
float scaleHeight = ((float) newHeight)/height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0,
width, height, matrix, true);
return resizedBitmap;
}