看看这个例子:
Make certain area of bitmap transparent on touch
这是一种使用渐变绘画的方法:
Paint framePaint = new Paint();
for(int i = 1; i < 5; i++){
setFramePaint(framePaint, i, imageW, imageH);
myCanvas.drawPaint(framePaint);
}
…
private void setFramePaint(Paint p, int side, float iw, float ih){
// paint, side of rect, image width, image height
p.setShader(null);
p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
float borderSize = 0.1f; //relative size of border
//use the smaller image size to calculate the actual border size
float bSize = (iw > ih)? ih * borderSize: ih * borderSize;
float g1x = 0;
float g1y = 0;
float g2x = 0;
float g2y = 0;
int c1 = 0, c2 = 0;
if (side == 1){<