需要根据纵横比调整图像(位图)的大小而不会降低质量和清晰度。我看到有些时候会失去质量,有些时候会失去一些时间。我希望在调整大小后可以获得高质量的图像,但可能并不完全需要高度和宽度。我用过: `
private Bitmap scaleToActualAspectRatio(Bitmap image) {
int maxWidth = getActivity().getWindowManager().getDefaultDisplay()
.getWidth();
int maxHeight = getActivity().getWindowManager().getDefaultDisplay()
.getHeight();
if (maxHeight > 0 && maxWidth > 0) {
int width = image.getWidth();
int height = image.getHeight();
float ratioBitmap = (float) width / (float) height;
float ratioMax = (float) maxWidth / (float) maxHeight;
int finalWidth = maxWidth;
int finalHeight = maxHeight;
if (ratioMax > 1) {
finalWidth = (int) ((float)maxHeight * ratioBitmap);
} else {
finalHeight = (int) ((float)maxWidth / ratioBitmap);
}
image = Bitmap.createScaledBitmap(image, finalWidth, finalHeight, true);
return image;
} else {
return image;
}`