An easy way to achieve this effect is to use Canvas.drawCircle()
and a BitmapShader
:
BitmapShader s = new BitmapShader(myPhoto, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
Paint p = new Paint();
p.setShader(s);
myCanvas.drawCircle(centerX, centerY, radius, p);
To do the shadow, simply call Paint.setShadowLayer()
on the paint (this will only work if you draw the effect into an offscreen Bitmap
or if your View
uses a software layer – set by calling View.setLayerType()
–).
The border can be drawn by drawing another circle on top, using the Paint.Style.STROKE
style (that you can set by calling Paint.setStyle()
).
Finally you can draw the gloss by drawing a circle, oval or Path
on top of your very first circle. You'll need to use a LinearGradient
shader on your paint and you'll also need to clip the gloss. You can do this in two ways:
- If you are drawing the entire effect into a
Bitmap
, which is what I would recommend, simply set the paint's Xfermode
to a new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)
.
- If you are drawing the effect directly on screen you can simply use
Canvas.clipPath()
to set a circular clip. Note that this will work with hardware acceleration only as of Android 4.3.