1

I am fetching a Bitmap with Parse on my Android application.

final WeakReference<ImageView> weakImageView = new WeakReference<>(imageViewToMask);
fetchFromParse(getContext(), new Success() {
        @Override
        public void success(Bitmap image) {
            if (weakImageView.get() != null) {
                // Here how to make this image a MaskDrawable to mask it?
                // MaskedDrawable d = new MaskedDrawable(bitmap, context, [canvas here]?)                
                // weakImageView.get().setImageDrawable(d);
                weakImageView.get().setImageDrawable(image);
            }
        }
});

Now I want to mask this bitmap with another image, I found this answer in this thread:

public class MaskedDrawable extends Drawable {

    public void draw(Bitmap original, Context context, Canvas canvas) {
            Bitmap mask = BitmapFactory.decodeResource(context.getResources(), R.drawable.mask_image);
            Bitmap result = Bitmap.createBitmap(mask.getWidth(), mask.getHeight(), Config.ARGB_8888);
            Canvas tempCanvas = new Canvas(result);
            Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
            paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
            tempCanvas.drawBitmap(original, 0, 0, null);
            tempCanvas.drawBitmap(mask, 0, 0, paint);
            paint.setXfermode(null);

            // How do I create this canvas user here?
            canvas.drawBitmap(result, 0, 0, new Paint());
    }

}

I already have the original bitmap and the context object, but I don't know how to use canvas. What to do?

Thanks for your help!

Rob
  • 4,123
  • 3
  • 33
  • 53

0 Answers0