先上效果。如下:
1、截取当前屏幕的内容(截屏)
/**
*获取当前Activity的截图
*
* @param activity
* 需要被截取的Activity
* @return 截图后的Bitmap对象
*/
public static Bitmap getScreenShot(Activity activity) {
View decorView = activity.getWindow().getDecorView();
View contentView = decorView.findViewById(android.R.id.content);
contentView.setDrawingCacheEnabled(true);
int tryNumber = 3;
Bitmap cache = null;
Bitmap bitmap = null;
while (tryNumber > 0) {
cache = contentView.getDrawingCache();
if (cache != null) {
bitmap = Bitmap.createBitmap(cache);
break;
}
tryNumber--;
}
contentView.setDrawingCacheEnabled(false);
return bitmap;
}
2、对图片进行高斯模糊处理(高斯模糊处理在我RenderScript实现高斯模糊中有写)
/**
* 对Bitmap进行高斯模糊处理
*
* @param bitmap
* 需要处理的Bitmap对象(处理完毕后将会覆盖之)
* @return 处理后的Bitmap对象
*/
public static Bitmap blurBitmap(Context context, Bitmap bitmap) {
RenderScript mRS = RenderScript.create(context);
ScriptIntrinsicBlur mS = ScriptIntrinsicBlur.create(mRS,
Element.U8_4(mRS));
Allocation inAllocation = Allocation.createFromBitmap(mRS, bitmap);
Allocation outAllocation = Allocation.createFromBitmap(mRS, bitmap);
mS.setRadius(18);// 模糊程度:0~25之间,越大越模糊
mS.setInput(inAllocation);
mS.forEach(outAllocation);
outAllocation.copyTo(bitmap);
mRS.destroy();
mRS = null;
return bitmap;
}