OnDraw中填充形状canvas.drawLine创建 [英] onDraw fill shape create with canvas.drawLine
问题描述
我为了绘制一个矩形画4条线(canvas.drawLine)。是否有可能以填充矩形区域? (我知道Android有一个rectDraw。煤矿是唯一的好奇心)
先谢谢了。
确定..我以前也路径创建一个路径段。继code ..请ü可以解释如何填写内部区域?
`涂料粉刷=新的油漆(Paint.ANTI_ALIAS_FLAG);
paint.setStrokeWidth(2);
paint.setColor(android.graphics.Color.RED);
paint.setStyle(Paint.Style.FILL_AND_STROKE);
paint.setAntiAlias(真);
path.reset();
path.setFillType(Path.FillType.INVERSE_EVEN_ODD);
path.moveTo(mPin [0] .getX()+ 10,mPin [0] .getY()+ 10);
path.lineTo(mPin [1] .getX()+ 10,mPin [1] .getY()+ 10); path.moveTo(mPin [1] .getX()+ 10,mPin [1] .getY()+ 10);
path.lineTo(mPin [3] .getX()+ 10,mPin [3] .getY()+ 10); path.moveTo(mPin [3] .getX()+ 10,mPin [3] .getY()+ 10);
path.lineTo(mPin [2] .getX()+ 10,mPin [2] .getY()+ 10); path.moveTo(mPin [2] .getX()+ 10,mPin [2] .getY()+ 10);
path.lineTo(mPin [0] .getX()+ 10,mPin [0] .getY()+ 10);
paint.setShader(新的LinearGradient(0,0,0,的getHeight(),Color.BLACK,Color.WHITE,Shader.TileMode.MIRROR));
c.drawPath(路径,油漆);`
您可以填充rect,如果你画的线段作为路径。但要只需填写由四个悬空,但相交线段围成的区域,我认为你必须编写自己的程序。搜索洪水填充或种子饱满。
i draw 4 lines (canvas.drawLine) in order to draw a rectangle. Is there any possibility to fill the area of the rectangle? (I know that android have a rectDraw. Mine is only curiosity)
thanks in advance.
ok.. I ve also a path created a path segment. Following the code.. Please can u explain how fill the internal area?
`Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setStrokeWidth(2);
paint.setColor(android.graphics.Color.RED);
paint.setStyle(Paint.Style.FILL_AND_STROKE);
paint.setAntiAlias(true);
path.reset();
path.setFillType(Path.FillType.INVERSE_EVEN_ODD);
path.moveTo(mPin[0].getX() + 10, mPin[0].getY() + 10);
path.lineTo(mPin[1].getX() + 10, mPin[1].getY() + 10);
path.moveTo(mPin[1].getX() + 10, mPin[1].getY() + 10);
path.lineTo(mPin[3].getX() + 10, mPin[3].getY() + 10);
path.moveTo(mPin[3].getX() + 10, mPin[3].getY() + 10);
path.lineTo(mPin[2].getX() + 10, mPin[2].getY() + 10);
path.moveTo(mPin[2].getX() + 10, mPin[2].getY() + 10);
path.lineTo(mPin[0].getX() + 10, mPin[0].getY() + 10);
paint.setShader(new LinearGradient(0, 0, 0, getHeight(), Color.BLACK, Color.WHITE, Shader.TileMode.MIRROR));
c.drawPath(path, paint);`
You could fill the rect if you drew your line segments as a Path. But to just fill an area bounded by four unconnected but intersecting line segments, I think you'd have to write your own routine. Search for "flood fill" or "seed fill".
这篇关于OnDraw中填充形状canvas.drawLine创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!