您的位置:首页 > 移动开发 > Android开发

Android 关于对某个 view 的截图和截图之后再对 view的图片进行高斯模糊效果

2017-02-09 12:58 645 查看
1》首先如果进入activity 时就需要模糊这里估计你要定义一个子线程 了,因为我试了几次直接不用子线程的例子都报bitmap控制真的问题。

所以就来试试 子线程进入截图高斯模糊:

1.

//控制截图
new Thread(new Runnable() {
@Override
public void run() {
handler.sendEmptyMessageDelayed(1,100);
}
}).start();


2.

Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);

if (lay2.isShown()){
try {
takeScreenShot(lay2);
}catch (Exception e){
Log.e("--------","----------"+e);
}
}else {
handler.sendEmptyMessageDelayed(1,100);
Log.e("--------","-------222222---");
}

}
};

3.

/**
* 高斯模糊
* @param bitmap
* @return
*/
public Bitmap blurBitmap(Bitmap bitmap){

//Let's create an empty bitmap with the same size of the bitmap we want to blur
Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
//Instantiate a new Renderscript
RenderScript rs = RenderScript.create(getApplicationContext());
//Create an Intrinsic Blur Script using the Renderscript
ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
//Create the Allocations (in/out) with the Renderscript and the in/out bitmaps
Allocation allIn = Allocation.createFromBitmap(rs, bitmap);
Allocation allOut = Allocation.createFromBitmap(rs, outBitmap);
//Set the radius of the blur: 0 < radius <= 25
blurScript.setRadius(10.0f);
//Perform the Renderscript
blurScript.setInput(allIn);
blurScript.forEach(allOut);
//Copy the final bitmap created by the out Allocation to the outBitmap
allOut.copyTo(outBitmap);
//recycle the original bitmap
bitmap.recycle();
//After finishing everything, we destroy the Renderscript.
rs.destroy();
return outBitmap;
}

/**
* 截图
* @param view
*/
public void takeScreenShot(View view){
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap bitmap = view.getDrawingCache();
Log.e(">>>>>>>",">>>>>>>"+bitmap);
if (bitmap!=null){
wellet_bg.setImageBitmap(blurBitmap(bitmap));
}

}


4.换用你自己想截图模糊的view
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: