问题
I want to draw an image with the following shape on a canvas:
The black must be replaced by my image. I currently draw the image as a whole. I just don't know how I can get that sort of shape in it?
canvas.drawBitmap(header,0,0,mPaint);
Can someone help me?
回答1:
Thanks to pskink I've got it:
int width = this.getMeasuredWidth();
int height = this.getMeasuredHeight();
BitmapShader shader;
shader = new BitmapShader(header, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
mPaint.setShader(shader);
Path path = new Path();
path.moveTo(0,0);
path.lineTo(0,height/2);
path.lineTo(width,height/4);
path.lineTo(width,0);
canvas.drawPath(path,mPaint);
Just use a shader and a path to do the job.
来源:https://stackoverflow.com/questions/25641055/draw-an-bitmap-on-a-canvas-with-a-custom-shape