I am trying to create a reflection shadow and found an issue.
Please find the below code in my custom view:
@Override
protected void onDraw(Canvas ca
Considering the black rectangle in the second column:
PorterDuff.MODE.DST_IN is defined as [Sa*Da, Sa*Dc]. Since the destination pixels are a constant opaque grey (Da=1) the alpha channel of the result will be set to the alpha channel from your linear gradient, which ranges from 0.5 to 1.
And there is your problem right there... in the second column you are setting pixels of your Window canvas partially transparent. What shows through from underneath? The window background, which is still the default black.
In the 3rd column you are drawing to an offscreen bitmap first, and then drawing the partially-transparent offscreen bitmap to the Window canvas afterwards. This works because the incoming pixels (from the offscreen bitmap) do not completely replace the pixels already present but are blended with the destination buffer (in PorterDuff terms I think it's equivalent to SRC_ATOP).