我正在开发一个应用程序,在其中我从相机或图库中获取图像并对其应用过滤器。
当我将此图像从一个活动发送到另一个活动时,我必须缩小图像尺寸,这会使图像分辨率降低。
这是我的代码:
private Bitmap scaleBitmap(Bitmap bm) {
int width = bm.getWidth();
int height = bm.getHeight();
Log.v("Pictures", "Width and height are " + width + "--" + height);
int maxwidth,maxhieght;
if(width >2400) {
maxwidth= width/2;
} else{maxwidth =1200;}
if(height>2800){
maxhieght=height/2;
} else {
maxhieght=1400;
}
if (width > height) {
// landscape
float ratio = (float) width / maxwidth;
width = maxwidth;
height = (int)(height / ratio);
} else if (height > width) {
// portrait
float ratio = (float) height / maxhieght;
height = maxhieght;
width = (int)(width / ratio);
} else {
// square
height = 1200;
width = 1200;
}
Log.v("Pictures", "after scaling Width and height are " + width + "--" + height);
bm = Bitmap.createScaledBitmap(bm, width, height, true);
return bm;
}
有没有办法发送图像的实际尺寸?
提前谢谢。