我正在使用Bitmap.createScaledBitmap()
调整图片大小,但正如我刚检查过的那样,它会创建沉闷的图像或说低质量的图像。如果我能得到清晰的图像,请告诉我。
我正在使用这种方法,因为我想在将照片尺寸上传到服务器之前减小照片尺寸。
我的代码如下:
final int maxSize = 250;
int outWidth;
int outHeight;
int inWidth = selectedImage.getWidth();
int inHeight = selectedImage.getHeight();
if (inWidth > inHeight) {
outWidth = maxSize;
outHeight = (inHeight * maxSize) / inWidth;
} else {
outHeight = maxSize;
outWidth = (inWidth * maxSize) / inHeight;
}
Bitmap resizedBitmap = Bitmap.createScaledBitmap(selectedImage,
outWidth, outHeight, false);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
resizedBitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] data = baos.toByteArray();
String strBase64 = Base64.encodeToString(data, Base64.DEFAULT);