Draw an bitmap on a canvas with a custom shape

自闭症网瘾萝莉.ら 提交于 2019-12-14 03:57:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!