我用下面的代码将bitmap转化成Drawable,但是由于imageView的尺寸和Drawable尺寸不一样,结果显示出来没有完全填充。请问该怎么设置尺寸啊。感激不尽
Bitmap photo = extras.getParcelable("data");
Log.i("width = ",String.valueOf(photo.getWidth()));
Log.i("height = ",String.valueOf(photo.getHeight()));
//int width = photo.getWidth() * 2;
//int height = photo.getHeight() * 2;
//Matrix matrix = new Matrix();
//matrix.postScale(width,height);
//Bitmap photoBig = Bitmap.createBitmap(photo,0,0,photo.getWidth(),photo.getHeight(),matrix,true);
Drawable drawable = new BitmapDrawable(photo);
Log.i("photo width ",String.valueOf(ivUserphoto.getWidth()));
Log.i("photo height ",String.valueOf(ivUserphoto.getHeight()));
ivUserphoto.setImageDrawable(drawable);//ivUserphoto是显示用户头像的ImageView
打印结果
------解决思路----------------------
设置下imageview
android:scaleType="fitXY"
用代码也可以
iv.setScaleType(ScaleType.FIT_XY)
------解决思路----------------------
要完全填充可以是楼上那个,也可以直接设置给它的background属性,那样也不需要去拉升了
------解决思路----------------------
Bitmap.createScaledBitmap(Bitmap src, int dstWidth, int dstHeight, boolean filter)
此方法可以指定宽高对src进行缩放