How to blend two bitmaps using another bitmap as a mask?
<p>I'm writing an Android app and have hit a bit of a brick wall. I have two bitmaps (let's call them bitmap X and bitmap Y) containing two equally dimensioned images. In addition, I have a mask bitmap (call it M and also of equal dimensions) that only has alpha values and no color info. I want to combine these bitmaps so that pixels from X and Y blend together depending on the alpha value in bitmap M. I guess the pixel math should be something like:</p>

<p><code>Z = X*M/255 + Y*(255-M)/255</code></p>

<p>I could do this pixel by pixel but I thought using <code>paint.setXfermode</code> to draw these bitmaps directly onto the canvas would be more efficient. I tried to wrap my head around the PorterDuff modes but I can't seem to come up with the right combination. Anyone know what combo will produce what I want?</p>
