[英]Resize image(Bitmap) as per aspect ratio without loosing quality of image android?
需要调整图像(位图)的大小而不会因高宽比而丢失质量和清晰度。 我看到有些时候会失去质量,有些时候会失去一些时间。 我希望在调整大小后可以获得高质量的图像,但可能并不完全需要高度和宽度。 我用过:`
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;
}`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.