你可以像這樣同時加載的位圖和使用PorterDuffXfermode
和DST_IN
掩蓋「Bitmap2」,排序的:
Bitmap bitmap2 = BitmapFactory.decodeResource(getResources(), R.drawable.bitmap2);
Bitmap bitmap1 = BitmapFactory.decodeResource(getResources(), R.drawable.bitmap1);
Bitmap bitmap2MaskedByBitmap1 = Bitmap.createBitmap(bitmap2.getWidth(), bitmap2.getHeight(), bitmap2.getConfig());
Canvas canvas = new Canvas(bitmap2MaskedByBitmap1);
Paint paint = new Paint();
paint.setFilterBitmap(false);
canvas.drawBitmap(bitmap2, 0, 0, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
canvas.drawBitmap(bitmap1, 0, 0, paint);
bitmap2.recycle();
bitmap1.recycle();
// bitmap2MaskedByBitmap1 should now contain the desired image
// as long as your Bitmap1 mask isn't sh-t.
!大!謝謝!但現在我有黑色背景的圖像...我可以用空(alpha 0)背景來做到嗎? – user868395 2012-03-12 20:37:07
ok)任務完成)Mode.XOR – user868395 2012-03-12 21:22:47