+ static void setBackground(View v, Bitmap bm) {
+
+ if (bm == null) {
+ v.setBackgroundResource(0);
+ return;
+ }
+
+ int vwidth = v.getWidth();
+ int vheight = v.getHeight();
+ int bwidth = bm.getWidth();
+ int bheight = bm.getHeight();
+ float scalex = (float) vwidth / bwidth;
+ float scaley = (float) vheight / bheight;
+ float scale = Math.max(scalex, scaley) * 1.3f;
+
+ Bitmap.Config config = Bitmap.Config.ARGB_8888;
+ Bitmap bg = Bitmap.createBitmap(vwidth, vheight, config);
+ Canvas c = new Canvas(bg);
+ Paint paint = new Paint();
+ paint.setAntiAlias(true);
+ paint.setFilterBitmap(true);
+ ColorMatrix greymatrix = new ColorMatrix();
+ greymatrix.setSaturation(0);
+ ColorMatrix darkmatrix = new ColorMatrix();
+ darkmatrix.setScale(.3f, .3f, .3f, 1.0f);
+ greymatrix.postConcat(darkmatrix);
+ ColorFilter filter = new ColorMatrixColorFilter(greymatrix);
+ paint.setColorFilter(filter);
+ Matrix matrix = new Matrix();
+ matrix.setTranslate(-bwidth/2, -bheight/2); // move bitmap center to origin
+ matrix.postRotate(10);
+ matrix.postScale(scale, scale);
+ matrix.postTranslate(vwidth/2, vheight/2); // Move bitmap center to view center
+ c.drawBitmap(bm, matrix, paint);
+ v.setBackgroundDrawable(new BitmapDrawable(bg));
+ }
+