在具有自定义形状的画布上绘制位图 [英] Draw an bitmap on a canvas with a custom shape
本文介绍了在具有自定义形状的画布上绘制位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在画布上绘制以下形状的图像:
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);
有人可以帮助我吗?
推荐答案
感谢pskink我已经知道了:
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.
这篇关于在具有自定义形状的画布上绘制位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文