减小位图的大小在Android中一些特定的像素 [英] Reduce size of Bitmap to some specified pixel in Android
本文介绍了减小位图的大小在Android中一些特定的像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想减少我的位图图像尺寸最大的640px。比如我有尺寸的位图图像1200 * 1200像素。我怎样才能将其降低到640px。
I would like to reduce My Bitmap image size to maximum of 640px. For example I have Bitmap image of size 1200 x 1200 px .. How can I reduce it to 640px.
推荐答案
如果您通过位图的宽度和高度,然后使用下面的功能。
If you pass bitmap width and height then use below function.
public Bitmap getResizedBitmap(Bitmap image, int bitmapWidth,
int bitmapHeight) {
return Bitmap.createScaledBitmap(image, bitmapWidth, bitmapHeight,
true);
}
如果你想要的位图的比例相同,减少位图尺寸
。然后通过你的最大尺寸的位图。 您可以使用此功能
if you want bitmap ratio same and reduce bitmap size. then pass your maximum size bitmap. you can use this function
public Bitmap getResizedBitmap(Bitmap image, int maxSize) {
int width = image.getWidth();
int height = image.getHeight();
float bitmapRatio = (float)width / (float) height;
if (bitmapRatio > 0) {
width = maxSize;
height = (int) (width / bitmapRatio);
} else {
height = maxSize;
width = (int) (height * bitmapRatio);
}
return Bitmap.createScaledBitmap(image, width, height, true);
}
这篇关于减小位图的大小在Android中一些特定的像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文