Android 图像视图中设置的位图未获得填充父对象
我使用以下方法压缩了图像:Android 图像视图中设置的位图未获得填充父对象,android,Android,我使用以下方法压缩了图像: private Bitmap decodeFile(InputStream is){ //decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(is,null,o); //F
private Bitmap decodeFile(InputStream is){
//decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(is,null,o);
//Find the correct scale value. It should be the power of 2.
final int REQUIRED_SIZE=100;
int width_tmp=o.outWidth, height_tmp=o.outHeight;
int scale=1;
while(true){
if(width_tmp/2<REQUIRED_SIZE || height_tmp/2<REQUIRED_SIZE)
break;
width_tmp/=2;
height_tmp/=2;
scale*=2;
}
//decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize=scale;
return BitmapFactory.decodeStream(is, null, o2);
}
但是没有用
还有其他办法吗?这可能会解决问题
iv.setScaleType(ScaleType.FIT_XY);
在你的活动中使用这个
mImageView.setScaleType(ScaleType.FIT_XY);
或者在你的布局中
android:scaleType="fitXY"
android:scaleType="fitXY"