Android画像の重ね合わせ効果を実現
1304 ワード
方法1:
Bitmap bitmap1 = ((BitmapDrawable) info.icon).getBitmap();
Bitmap bitmap2 = ((BitmapDrawable) getResources()
.getDrawable(R.drawable.ic_assistive_touch_refresh)).getBitmap();
Drawable[] array = new Drawable[2];
array[0] = new BitmapDrawable(bitmap1);
array[1] = new BitmapDrawable(bitmap2);
LayerDrawable la = new LayerDrawable(array);
ShortcutsSetting.setImageDrawable(la);
方法二:
// Immutable bitmap passed to Canvas constructor Bitmap bitmap1 = BitmapFactory.decodeResource(getResources(), R.drawable.apple).copy(Bitmap.Config.ARGB_8888, true); Bitmap bitmap2 = ((BitmapDrawable) getResources().getDrawable( R.drawable.go)).getBitmap(); Bitmap newBitmap = null; newBitmap = Bitmap.createBitmap(bitmap1); Canvas canvas = new Canvas(newBitmap); Paint paint = new Paint(); int w = bitmap1.getWidth(); int h = bitmap1.getHeight(); int w_2 = bitmap2.getWidth(); int h_2 = bitmap2.getHeight(); paint.setColor(Color.GRAY); paint.setAlpha(125); canvas.drawRect(0, 0, bitmap1.getWidth(), bitmap1.getHeight(), paint); paint = new Paint(); canvas.drawBitmap(bitmap2, Math.abs(w - w_2) / 2, Math.abs(h - h_2) / 2, paint); canvas.save(Canvas.ALL_SAVE_FLAG); // canvas.restore(); image.setImageBitmap(newBitmap);