如何绘制路径工会的轮廓 [英] How to draw the contour of a union of Path
本文介绍了如何绘制路径工会的轮廓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我有六角路径的包和要绘制的路径工会的轮廓(境)。我想用地区,工会的路径,然后一起用得到getBoundaryPath()的边界产生的路径,但它汲取什么。
因此,有人可以告诉我,我怎么能有我所有的路径对象的工会的轮廓(境)?
@覆盖
保护无效的onDraw(帆布油画){
super.onDraw(画布);
//如果(pmBack!= NULL){
// canvas.drawBitmap(pmBack,新的Matrix(),涂料);
//} 如果(mCells!= NULL){ 的for(int i = 0; I< mCells.length;我++){
最后HexCell电池= mCells [I]
如果(细胞!= NULL){
最终的PointF P = cell.getDrawPoint();
paint.setColor(cell.mColor); 路径path = drawHexagon(cell.mSize,mCenterX + p.x,mCenterY + p.y);
canvas.drawPath(drawHexagon(cell.mSize,mCenterX + p.x,mCenterY + p.y),涂料); 如果(我== 0){
region.setPath(路径,mClip);
}其他{
region2.setPath(路径,mClip);
region.op(REGION2,Op.UNION);
}
}
}
canvas.drawPath(region.getBoundaryPath(),paintContour);
}}私人路径drawHexagon(最终浮动大小,浮动的centerX,浮centerY){
路径path =新路径();
的for(int i = 0; I< = 6;我++){
双角= 2 * Math.PI / 6 *(1 + 0.5);
浮动x_i =(浮点)(+的centerX大小* Math.cos(角度));
浮动y_i =(浮点)(centerY +尺寸* Math.sin(角度));
如果(我== 0){
path.moveTo(x_i,y_i);
}其他{
path.lineTo(x_i,y_i);
}
} 返回路径;
}
解决方案
尝试使用
路径轮廓= region.getBoundaryPath();
路径的新路径=新路径();
字模=新的Matrix();
matrix.setScale(1,1,0,0);
outline.transform(矩阵的新路径);
canvas.drawPath(的新路径,油漆);
而不是使用 getBoundaryPath 直接
Hello i have a pack of Hexagon Path and a want to draw the contour(border) of the union of those Path. I thought of using Region, to union the Path together then get the border resulting Path with getBoundaryPath(), but it draw nothing. So can someone tell me how can I have the contour(border) of the union of all my Path objects ?
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// if (pmBack != null) {
// canvas.drawBitmap(pmBack, new Matrix(), paint);
// }
if (mCells != null) {
for (int i = 0; i < mCells.length; i++) {
final HexCell cell = mCells[i];
if (cell != null) {
final PointF p = cell.getDrawPoint();
paint.setColor(cell.mColor);
Path path = drawHexagon(cell.mSize, mCenterX + p.x, mCenterY + p.y);
canvas.drawPath(drawHexagon(cell.mSize, mCenterX + p.x, mCenterY + p.y), paint);
if (i == 0) {
region.setPath(path, mClip);
} else {
region2.setPath(path, mClip);
region.op(region2, Op.UNION);
}
}
}
canvas.drawPath(region.getBoundaryPath(), paintContour);
}
}
private Path drawHexagon(final float size, float centerX, float centerY) {
Path path = new Path();
for (int i = 0; i <= 6; i++) {
double angle = 2 * Math.PI / 6 * (i + 0.5);
float x_i = (float) (centerX + size * Math.cos(angle));
float y_i = (float) (centerY + size * Math.sin(angle));
if (i == 0) {
path.moveTo(x_i, y_i);
} else {
path.lineTo(x_i, y_i);
}
}
return path;
}
解决方案
Try using
Path outline = region.getBoundaryPath();
Path newpath = new Path();
Matrix matrix = new Matrix();
matrix.setScale(1, 1, 0, 0);
outline.transform(matrix,newpath);
canvas.drawPath(newpath, paint);
instead of using getBoundaryPath directly.
这篇关于如何绘制路径工会的轮廓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文