3

I want to draw an image with the following shape on a canvas:

enter image description here

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?

user1007522
  • 7,858
  • 17
  • 69
  • 113

1 Answers1

6

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.

David Medenjak
  • 33,993
  • 14
  • 106
  • 134
user1007522
  • 7,858
  • 17
  • 69
  • 113