Skip to content

Instantly share code, notes, and snippets.

@wuqian
Created October 14, 2014 05:44
Show Gist options
  • Save wuqian/58b0909c6c387beb3437 to your computer and use it in GitHub Desktop.
Save wuqian/58b0909c6c387beb3437 to your computer and use it in GitHub Desktop.
android blur
private Bitmap blur(Bitmap sentBitmap, Context context) {
Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
final RenderScript rs = RenderScript.create(context);
final Allocation input = Allocation.createFromBitmap(rs, sentBitmap, Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);
final Allocation output = Allocation.createTyped(rs, input.getType());
final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
script.setRadius(10.f /* e.g. 3.f */);
script.setInput(input);
script.forEach(output);
output.copyTo(bitmap);
sentBitmap.recycle();
return bitmap;
}
// called from PanelView when self-expanding, too
public void startOpeningPanel(PanelView panel) {
if (DEBUG) LOG("startOpeningPanel: " + panel);
mTouchingPanel = panel;
mPanelHolder.setSelectedPanel(mTouchingPanel);
for (PanelView pv : mPanels) {
if (pv != panel) {
pv.collapse();
}
}
WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Bitmap screenBitmap = SurfaceControl.screenshot(1920 /10, 1080 /10);
Matrix matrix = new Matrix();
int rDegree = 0;
switch (display.getRotation()) {
case Surface.ROTATION_0:
rDegree = 0;
break;
case Surface.ROTATION_90:
rDegree = 270;
break;
case Surface.ROTATION_180:
rDegree = 180;
break;
case Surface.ROTATION_270:
rDegree = 90;
break;
}
matrix.postRotate(rDegree);
Bitmap rotate = Bitmap.createBitmap(screenBitmap , 0, 0,
screenBitmap.getWidth(), screenBitmap.getHeight(), matrix, true);
mTouchingPanel.setBackgroundBitmap(blur(rotate, mContext));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment