代码如下
xml :
<FrameLayout android:layout_width="match_parent" android:layout_height="300dp"> <ImageView android:id="@+id/old_image" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="fitXY" android:src="@drawable/test"/> <ImageView android:id="@+id/blur_image" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="fitXY"/> </FrameLayout>
Activity :
private ImageView old_image, blur_image; private Bitmap mBitmap, overlay; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); old_image = (ImageView) findViewById(R.id.old_image); blur_image = (ImageView) findViewById(R.id.blur_image); //设置模糊图片的长和宽 ViewGroup.LayoutParams params = blur_image.getLayoutParams(); params.height = 600; params.width = ViewGroup.LayoutParams.MATCH_PARENT; blur_image.setLayoutParams(params); //得到模糊图片 if (null != overlay) { blur_image.setImageBitmap(overlay); } //将old_image对象转化为bitmap对象 old_image.buildDrawingCache(); mBitmap = old_image.getDrawingCache(); mBitmap = ((BitmapDrawable) old_image.getDrawable()).getBitmap(); //这两个数字是控制模糊度的