本文整理汇总了Java中android.graphics.Canvas.drawPath方法的典型用法代码示例。如果您正苦于以下问题:Java Canvas.drawPath方法的具体用法?Java Canvas.drawPath怎么用?Java Canvas.drawPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.Canvas
的用法示例。
在下文中一共展示了Canvas.drawPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawTriangle
import android.graphics.Canvas; //导入方法依赖的package包/类
private void drawTriangle(Canvas c, float startAngle, float sweepAngle, Rect bounds) {
if (this.mShowArrow) {
if (this.mArrow == null) {
this.mArrow = new Path();
this.mArrow.setFillType(FillType.EVEN_ODD);
} else {
this.mArrow.reset();
}
float inset = ((float) (((int) this.mStrokeInset) / 2)) * this.mArrowScale;
float x = (float) ((this.mRingCenterRadius * Math.cos(0.0d)) + ((double) bounds.exactCenterX()));
float y = (float) ((this.mRingCenterRadius * Math.sin(0.0d)) + ((double) bounds.exactCenterY()));
this.mArrow.moveTo(0.0f, 0.0f);
this.mArrow.lineTo(((float) this.mArrowWidth) * this.mArrowScale, 0.0f);
this.mArrow.lineTo((((float) this.mArrowWidth) * this.mArrowScale) / 2.0f, ((float) this.mArrowHeight) * this.mArrowScale);
this.mArrow.offset(x - inset, y);
this.mArrow.close();
this.mArrowPaint.setColor(this.mCurrentColor);
c.rotate((startAngle + sweepAngle) - 5.0f, bounds.exactCenterX(), bounds.exactCenterY());
c.drawPath(this.mArrow, this.mArrowPaint);
}
}
示例2: draw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public void draw(Canvas canvas, Paint paint, float opacity) {
opacity *= mOpacity;
if (opacity > MIN_OPACITY_FOR_DRAW) {
saveAndSetupCanvas(canvas);
if (mPath == null) {
throw new JSApplicationIllegalArgumentException(
"Shapes should have a valid path (d) prop");
}
if (setupFillPaint(paint, opacity)) {
canvas.drawPath(mPath, paint);
}
if (setupStrokePaint(paint, opacity)) {
canvas.drawPath(mPath, paint);
}
restoreCanvas(canvas);
}
markUpdateSeen();
}
示例3: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
if (getDrawable() == null) {
return;
}
RectF rect = new RectF(getPaddingLeft(), getPaddingTop(), getRight()
- getLeft() - getPaddingRight(), getBottom() - getTop()
- getPaddingBottom());
Path path = new Path();
if (mArrowLocation == LOCATION_LEFT) {
leftPath(rect, path);
} else {
rightPath(rect, path);
}
canvas.drawPath(path, mBitmapPaint);
drawText(canvas, mAngle);
}
示例4: draw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public void draw(@NonNull Canvas canvas) {
canvas.save();
updateBorderOutline();
//Shader uses alpha as well.
mPaint.setAlpha(255);
if (mPathForBorderOutline != null) {
int useColor = WXViewUtils.multiplyColorAlpha(mColor, mAlpha);
if (mShader != null) {
mPaint.setShader(mShader);
mPaint.setStyle(Paint.Style.FILL);
canvas.drawPath(mPathForBorderOutline, mPaint);
mPaint.setShader(null);
} else if ((useColor >>> 24) != 0) {
mPaint.setColor(useColor);
mPaint.setStyle(Paint.Style.FILL);
canvas.drawPath(mPathForBorderOutline, mPaint);
mPaint.setShader(null);
}
}
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
drawBorders(canvas);
mPaint.setShader(null);
canvas.restore();
}
示例5: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
final int width = getWidth();
//重置画笔
path.reset();
//绘制贝塞尔曲线
path.lineTo(0, headHeight);
path.quadTo(width / 2, headHeight + waveHeight, width, headHeight);
path.lineTo(width, 0);
canvas.drawPath(path, paint);
}
示例6: drawRoundedBorders
import android.graphics.Canvas; //导入方法依赖的package包/类
private void drawRoundedBorders(Canvas canvas) {
if (mBackgroundColor != 0) {
PAINT.setColor(mBackgroundColor);
canvas.drawPath(getPathForBorderRadius(), PAINT);
}
drawBorders(canvas);
}
示例7: paintTriplet
import android.graphics.Canvas; //导入方法依赖的package包/类
public void paintTriplet(Triplet triplet, Canvas canvas, Paint tripletPaint,
Junction junctionsArray[], Path tripletPath) {
int junctionNo1 = triplet.getJunctionNo1();
int junctionNo2 = triplet.getJunctionNo2();
int junctionNo3 = triplet.getJunctionNo3();
tripletPath.reset();
tripletPath.moveTo(junctionsArray[junctionNo1].getX(), junctionsArray[junctionNo1].getY());
tripletPath.lineTo(junctionsArray[junctionNo2].getX(), junctionsArray[junctionNo2].getY());
tripletPath.lineTo(junctionsArray[junctionNo3].getX(), junctionsArray[junctionNo3].getY());
canvas.drawPath(tripletPath, tripletPaint);
}
示例8: drawVertLine
import android.graphics.Canvas; //导入方法依赖的package包/类
private void drawVertLine(Canvas c)
{
path.reset();
path.moveTo(rect.centerX(), rect.top);
path.lineTo(rect.centerX(), rect.bottom);
c.drawPath(path, paint);
}
示例9: drawProgressRectBackground
import android.graphics.Canvas; //导入方法依赖的package包/类
private void drawProgressRectBackground(Canvas canvas, int paintColor) {
canvas.save();
canvas.translate(getPaddingLeft(), getPaddingTop());
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setColor(paintColor);
drawRoundRectPath();
canvas.drawPath(mRoundRectPath, mPaint);
canvas.restore();
}
示例10: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
if (excludeSide != EXCLUDE_ALL) {
canvas.getClipBounds(mDrawRect);
mPath = PathHelper.calculatePath(this, mPath, mDrawRect, excludeSide);
canvas.drawPath(mPath, strokePaint);
}
super.onDraw(canvas);
}
示例11: drawDebugIndicator
import android.graphics.Canvas; //导入方法依赖的package包/类
private void drawDebugIndicator(Canvas canvas) {
DEBUG_PAINT.setColor(WHITE);
Path path = getTrianglePath(0, 0, (int) (16 * density));
canvas.drawPath(path, DEBUG_PAINT);
DEBUG_PAINT.setColor(loadedFrom.debugColor);
path = getTrianglePath(0, 0, (int) (15 * density));
canvas.drawPath(path, DEBUG_PAINT);
}
示例12: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// 画布整体向上偏移
canvas.translate(0, -Utils.getStatusBarHeight(getResources()));
stickyRadius = getStickyRadius();
// 3、根据 dragCenter 动态计算 dragPoint 和 stickyPoint
// dragPoint: 2圆圆心连线的垂线与 drag 圆的交点
// stickyPoint: 2圆圆心连线的垂线与 sticky 圆的交点
float xOffset = dragCenter.x - stickyCenter.x;
float yOffset = dragCenter.y - stickyCenter.y;
if (xOffset != 0) {
// 斜率
lineK = yOffset / xOffset;
}
dragPoint = GeometryUtil.getIntersectionPoints(dragCenter, dragRadius, lineK);
stickyPoint = GeometryUtil.getIntersectionPoints(stickyCenter, stickyRadius, lineK);
controlPoint = GeometryUtil.getPointByPercent(dragCenter, stickyCenter, 0.618f);
// 1、绘制圆
// 绘制拖拽圆
canvas.drawCircle(dragCenter.x, dragCenter.y, dragRadius, paint);
if (!isDragOutOfRange) {
// 绘制固定圆
canvas.drawCircle(stickyCenter.x, stickyCenter.y, stickyRadius, paint);
// 2、使用贝塞尔曲线绘制连接部分
Path path = new Path();
// 设置起点
path.moveTo(stickyPoint[0].x, stickyPoint[0].y);
// 使用贝塞尔曲线连接
path.quadTo(controlPoint.x, controlPoint.y, dragPoint[0].x, dragPoint[0].y);
// 连线
path.lineTo(dragPoint[1].x, dragPoint[1].y);
path.quadTo(controlPoint.x, controlPoint.y, stickyPoint[1].x, stickyPoint[1].y);
// path.close(); // 默认关闭
canvas.drawPath(path, paint); // 绘制
}
// 绘制圈圈,以固定圆圆心为圆心,然后80为半径
paint.setStyle(Paint.Style.STROKE);// 设置只有边线
canvas.drawCircle(stickyCenter.x, stickyCenter.y, maxDistance, paint);
paint.setStyle(Paint.Style.FILL);
}
示例13: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawColor(Color.TRANSPARENT);
if (out) {
float dr = c2.r / 2 + c2.r * 4 * (brokenProgress / 100f);
Log.i("info", "dr" + dr);
canvas.drawCircle(c2.x, c2.y, c2.r / (brokenProgress + 1), paint);
canvas.drawCircle(c2.x - dr, c2.y - dr, c2.r / (brokenProgress + 2), paint);
canvas.drawCircle(c2.x + dr, c2.y - dr, c2.r / (brokenProgress + 2), paint);
canvas.drawCircle(c2.x - dr, c2.y + dr, c2.r / (brokenProgress + 2), paint);
canvas.drawCircle(c2.x + dr, c2.y + dr, c2.r / (brokenProgress + 2), paint);
} else {
// 绘制手指跟踪的圆形
if (catchBitmap == null || (catchBitmap != null && catchBitmap.isRecycled())) {
return;
}
canvas.drawBitmap(catchBitmap, c2.x - c2.r, c2.y - c2.r, paint);
path.reset();
float deltaX = c2.x - c1.x;
float deltaY = -(c2.y - c1.y);
double distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
double sin = deltaY / distance;
double cos = deltaX / distance;
nearby = distance < c2.r * maxDistance;
if (nearby && !broken) {
canvas.drawCircle(c1.x, c1.y, c1.r, paint);
path.moveTo((float) (c1.x - c1.r * sin), (float) (c1.y - c1.r * cos));
path.lineTo((float) (c1.x + c1.r * sin), (float) (c1.y + c1.r * cos));
path.quadTo((c1.x + c2.x) / 2, (c1.y + c2.y) / 2, (float) (c2.x + c2.r * sin), (float) (c2.y + c2.r
* cos));
path.lineTo((float) (c2.x - c2.r * sin), (float) (c2.y - c2.r * cos));
path.quadTo((c1.x + c2.x) / 2, (c1.y + c2.y) / 2, (float) (c1.x - c1.r * sin), (float) (c1.y - c1.r
* cos));
canvas.drawPath(path, paint);
} else {
broken = true; // 已经拉断了
}
}
}
示例14: draw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
public void draw(Canvas canvas) {
Rect bounds = getBounds();
switch (mType) {
case CLIPPING:
int saveCount = canvas.save();
// clip, note: doesn't support anti-aliasing
mPath.setFillType(Path.FillType.EVEN_ODD);
canvas.clipPath(mPath);
super.draw(canvas);
canvas.restoreToCount(saveCount);
break;
case OVERLAY_COLOR:
super.draw(canvas);
mPaint.setColor(mOverlayColor);
mPaint.setStyle(Paint.Style.FILL);
mPath.setFillType(Path.FillType.INVERSE_EVEN_ODD);
canvas.drawPath(mPath, mPaint);
if (mIsCircle) {
// INVERSE_EVEN_ODD will only draw inverse circle within its bounding box, so we need to
// fill the rest manually if the bounds are not square.
float paddingH = (bounds.width() - bounds.height() + mBorderWidth) / 2f;
float paddingV = (bounds.height() - bounds.width() + mBorderWidth) / 2f;
if (paddingH > 0) {
canvas.drawRect(bounds.left, bounds.top, bounds.left + paddingH, bounds.bottom, mPaint);
canvas.drawRect(
bounds.right - paddingH,
bounds.top,
bounds.right,
bounds.bottom,
mPaint);
}
if (paddingV > 0) {
canvas.drawRect(bounds.left, bounds.top, bounds.right, bounds.top + paddingV, mPaint);
canvas.drawRect(
bounds.left,
bounds.bottom - paddingV,
bounds.right,
bounds.bottom,
mPaint);
}
}
break;
}
if (mBorderColor != Color.TRANSPARENT) {
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setColor(mBorderColor);
mPaint.setStrokeWidth(mBorderWidth);
mPath.setFillType(Path.FillType.EVEN_ODD);
canvas.drawPath(mBorderPath, mPaint);
}
}
示例15: renderOnCanvas
import android.graphics.Canvas; //导入方法依赖的package包/类
private void renderOnCanvas(Canvas canvas, float scale) {
canvas.save();
canvas.scale(scale, scale);
mTempPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
// Draw the pattern by creating the paths, adjusting the colors and drawing them. The path
// values are extracted from the SVG of the pattern file.
if (sPatternPaths == null) {
sPatternPaths = new Path[NUM_PATHS];
// Lightness values of the pattern, range 0 - 255
sPatternLightness = new int[] { 10, 40, 51, 66, 91, 112, 130 };
Path p = sPatternPaths[0] = new Path();
p.moveTo(1029.4f, 357.5f);
p.lineTo(1366f, 759.1f);
p.lineTo(1366f, 0f);
p.lineTo(1137.7f, 0f);
p.close();
p = sPatternPaths[1] = new Path();
p.moveTo(1138.1f, 0f);
p.rLineTo(-144.8f, 768f);
p.rLineTo(372.7f, 0f);
p.rLineTo(0f, -524f);
p.cubicTo(1290.7f, 121.6f, 1219.2f, 41.1f, 1178.7f, 0f);
p.close();
p = sPatternPaths[2] = new Path();
p.moveTo(949.8f, 768f);
p.rCubicTo(92.6f, -170.6f, 213f, -440.3f, 269.4f, -768f);
p.lineTo(585f, 0f);
p.rLineTo(2.1f, 766f);
p.close();
p = sPatternPaths[3] = new Path();
p.moveTo(471.1f, 768f);
p.rMoveTo(704.5f, 0f);
p.cubicTo(1123.6f, 563.3f, 1027.4f, 275.2f, 856.2f, 0f);
p.lineTo(476.4f, 0f);
p.rLineTo(-5.3f, 768f);
p.close();
p = sPatternPaths[4] = new Path();
p.moveTo(323.1f, 768f);
p.moveTo(777.5f, 768f);
p.cubicTo(661.9f, 348.8f, 427.2f, 21.4f, 401.2f, 25.4f);
p.lineTo(323.1f, 768f);
p.close();
p = sPatternPaths[5] = new Path();
p.moveTo(178.44286f, 766.85714f);
p.lineTo(308.7f, 768f);
p.cubicTo(381.7f, 604.6f, 481.6f, 344.3f, 562.2f, 0f);
p.lineTo(0f, 0f);
p.close();
p = sPatternPaths[6] = new Path();
p.moveTo(146f, 0f);
p.lineTo(0f, 0f);
p.lineTo(0f, 768f);
p.lineTo(394.2f, 768f);
p.cubicTo(327.7f, 475.3f, 228.5f, 201f, 146f, 0f);
p.close();
}
for (int i = 0; i < NUM_PATHS; i++) {
// Color is 0xAARRGGBB, so alpha << 24 will create a color with (alpha)% black.
// Although the color components don't really matter, since the backing bitmap cache is
// ALPHA_8.
mTempPaint.setColor(sPatternLightness[i] << 24);
canvas.drawPath(sPatternPaths[i], mTempPaint);
}
canvas.restore();
mTempPaint.reset();
}