我试图用模式填充位图。
你能告诉我,我做错了什么,如果你建议我采取一些方法。
public Bitmap applyMask(Context context, int resOriginal, int maskToBeApplied) {
Bitmap original = BitmapFactory.decodeResource(context.getResources(), resOriginal);
int width = original.getWidth();
int height = original.getHeight();
// decode mask
Bitmap mask = BitmapFactory.decodeResource(context.getResources(), maskToBeApplied);
// create output bitmap
Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
// create canvas
Canvas canvas = new Canvas(output);
// draw original (shirt)
canvas.drawBitmap(original, 0, 0, null);
// draw mask on shirt
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT));
// draw mask
canvas.drawBitmap(mask, 300, 400, paint);
// recycle used bitmaps
original.recycle();
mask.recycle();
return output;
}