本文整理汇总了Java中android.graphics.PathMeasure.setPath方法的典型用法代码示例。如果您正苦于以下问题:Java PathMeasure.setPath方法的具体用法?Java PathMeasure.setPath怎么用?Java PathMeasure.setPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.PathMeasure
的用法示例。
在下文中一共展示了PathMeasure.setPath方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initPath
import android.graphics.PathMeasure; //导入方法依赖的package包/类
/**
* 初始化 Path
*/
private void initPath() {
mSearchPath = new Path();
mCirclePath = new Path();
mMeasure = new PathMeasure();
RectF oval1 = new RectF(-50, -50, 50, 50);
mSearchPath.addArc(oval1, 45, 359.9f); // 放大镜的圆框
RectF oval2 = new RectF(-100, -100, 100, 100);
mCirclePath.addArc(oval2, 45, 359.9f); // 搜索的圆圈
float[] pos = new float[2];
mMeasure.setPath(mCirclePath, false);
mMeasure.getPosTan(0, pos, null); // 放大镜手柄的末端
mSearchPath.lineTo(pos[0], pos[1]); // 放大镜的手柄
}
示例2: warpStraightLines
import android.graphics.PathMeasure; //导入方法依赖的package包/类
/**
* Make sure it can be seen in "FILL" mode
*/
private void warpStraightLines() {
PathMeasure pmTemp = new PathMeasure();
for (int i = 0; i < mConfig.complexity; i++) {
if(lineRifts[i].isStraight())
{
pmTemp.setPath(lineRifts[i], false);
lineRifts[i].setStartLength(pmTemp.getLength() / 2);
float[] pos = new float[2];
pmTemp.getPosTan(pmTemp.getLength() / 2, pos, null);
int xRandom = (int) (pos[0] + Utils.nextInt(-Utils.dp2px(1), Utils.dp2px(1)));
int yRandom = (int) (pos[1] + Utils.nextInt(-Utils.dp2px(1), Utils.dp2px(1)));
lineRifts[i].reset();
lineRifts[i].moveTo(0,0);
lineRifts[i].lineTo(xRandom,yRandom);
lineRifts[i].lineToEnd();
}
}
}
示例3: draw
import android.graphics.PathMeasure; //导入方法依赖的package包/类
void draw(Canvas canvas, Paint paint, int color, float size, Path path) {
PathMeasure mPathMeasure = new PathMeasure();
float[] mPosition = new float[2];
float[] mTan = new float[2];
mPathMeasure.setPath(path, false);
paint.setAntiAlias(true);
paint.setColor(color);
paint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
Bitmap brush;
// done this way because of a bug in
// Bitmap.createScaledBitmap(getBrush(),(int) size,(int) size,true);
brush = createScaledBitmap(getBrush(), (int) size, (int) size, true);
float len = mPathMeasure.getLength();
float s2 = size / 2;
float step = s2 / 8;
for (float i = 0; i < len; i += step) {
mPathMeasure.getPosTan(i, mPosition, mTan);
// canvas.drawCircle(pos[0], pos[1], size, paint);
canvas.drawBitmap(brush, mPosition[0] - s2, mPosition[1] - s2, paint);
}
}
示例4: initPath
import android.graphics.PathMeasure; //导入方法依赖的package包/类
private void initPath() {
innerCircle = new Path();
outerCircle = new Path();
trangle1 = new Path();
trangle2 = new Path();
drawPath = new Path();
pathMeasure = new PathMeasure();
RectF innerRect = new RectF(-220, -220, 220, 220);
RectF outerRect = new RectF(-280, -280, 280, 280);
innerCircle.addArc(innerRect, 150, -359.9F); // 不能取360f,否则可能造成测量到的值不准确
outerCircle.addArc(outerRect, 60, -359.9F);
pathMeasure.setPath(innerCircle, false);
float[] pos = new float[2];
pathMeasure.getPosTan(0, pos, null); // 获取开始位置的坐标
trangle1.moveTo(pos[0], pos[1]);
pathMeasure.getPosTan((1f / 3f) * pathMeasure.getLength(), pos, null);
System.out.println("pos : " + pos[0] + " " + pos[1]);
trangle1.lineTo(pos[0], pos[1]);
pathMeasure.getPosTan((2f / 3f) * pathMeasure.getLength(), pos, null);
trangle1.lineTo(pos[0], pos[1]);
trangle1.close();
pathMeasure.getPosTan((2f / 3f) * pathMeasure.getLength(), pos, null);
Matrix matrix = new Matrix();
matrix.postRotate(-180);
trangle1.transform(matrix, trangle2);
}
示例5: initPath
import android.graphics.PathMeasure; //导入方法依赖的package包/类
/**
* 初始化球体弹跳的路径
*/
private void initPath() {
path.reset();
float intervalX = (viewWidth - 2 * defaultPadding) / (bounceCount + 1); //每次弹跳的间距
PointF start = new PointF();//起点位置
PointF control = new PointF(); //贝塞尔控制点
PointF end = new PointF(); //贝塞尔结束点
start.x = defaultPadding;
start.y = viewHeight - defaultPaddingBottom;
float controlOffsetY = viewHeight * 0.6f; //控制点向上偏移量,0.6为调试值
float deltaY = (1.2f * viewHeight + controlOffsetY) / (bounceCount + 1); //控制点高度递减值,1.2为调试值
PathMeasure tempPathMeasure = new PathMeasure();
segmentLength = new float[bounceCount + 1];
for (int i = 0; i <= bounceCount; i++) {
control.x = start.x + intervalX * (i + 0.5f);
control.y = -controlOffsetY + deltaY * i;
end.x = start.x + intervalX * (i + 1);
end.y = start.y;
if (i == 0) {
path.moveTo(start.x, start.y);
}
if (i == bounceCount) {
end.y = viewHeight;
}
path.quadTo(control.x, control.y, end.x, end.y);
tempPathMeasure.setPath(path, false);
if (i == 0) { //第一次弹跳的上升阶段不画,记录弹跳一半长度(为效果更好,实际取值0.45
skipLength = tempPathMeasure.getLength() * 0.45f;
}
segmentLength[i] = tempPathMeasure.getLength();
}
pathMeasure.setPath(path, false);
if (interCreater == null) {
interCreater = new MultiDecelerateAccelerateInterpolator();
}
physicInterpolator = interCreater.createInterpolator(segmentLength);
// Log.d("ccy","total length = " + pathMeasure.getLength());
// for (int i = 0; i < segmentLength.length; i++) {
// Log.d("ccy","i = " + i +";length = " + segmentLength[i]);
// }
}
示例6: onDraw
import android.graphics.PathMeasure; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
mPaint.setColor(getResources().getColor(R.color.colorAccent));
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(10);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setAntiAlias(true);
canvas.save();
canvas.translate(mWidth / 2, mHeight / 2);
// Path 直线操作
Path path = new Path();
path.lineTo(200, 200);
path.setLastPoint(200, 100);
path.lineTo(200, 0);
path.close();
path.moveTo(400, 200);
path.lineTo(400, 0);
path.addRect(-300, -300, 300, 300, Path.Direction.CCW);
path.setLastPoint(-400, 400);
canvas.drawPath(path, mPaint);
// Path 基本图形操作
mPaint.setColor(getResources().getColor(R.color.colorPrimary));
Path path1 = new Path();
Path path2 = new Path();
path1.addRect(-100, -100, 100, 100, Path.Direction.CW);
path2.addCircle(0, 0, 100, Path.Direction.CW);
path1.addPath(path2, 0, -100);
canvas.drawPath(path1, mPaint);
// Path 弧线操作
RectF rectF = new RectF(0, -400, 100, -300);
Path path3 = new Path();
path3.moveTo(0, -300);
path3.lineTo(100, -200);
path3.arcTo(rectF, 180, 180, true);
canvas.drawPath(path3, mPaint);
Path path4 = new Path();
Path path5 = new Path();
path4.addCircle(0, -600, 100, Path.Direction.CW);
path5.addRect(-100, -700, 100, -500, Path.Direction.CW);
path4.offset(100, 0, path5); // offset(float dx, float dy, Path dst) 中的 dx 和 dy 是偏移量,不是绝对量
canvas.drawPath(path4, mPaint);
mPaint.setColor(getResources().getColor(R.color.colorAccent));
canvas.drawPath(path5, mPaint);
Path path6 = new Path();
path6.addCircle(0, 0, 300, Path.Direction.CW);
PathMeasure pathMeasure = new PathMeasure();
pathMeasure.setPath(path6, false);
Path dst = new Path();
pathMeasure.getSegment(pathMeasure.getLength() * 1.2f, pathMeasure.getLength() * 1.5f, dst, true);
canvas.drawPath(dst, mPaint);
}
示例7: measurePaths
import android.graphics.PathMeasure; //导入方法依赖的package包/类
/**
* Perform measurements and pre-calculations. This should be called any time
* the view measurements or visuals are changed, such as with a call to {@link #setPadding(int, int, int, int)}
* or an operating system callback like {@link #onLayout(boolean, int, int, int, int)}.
*/
private void measurePaths() {
int maxSize;
float middle;
maxSize = Math.min(getWidth(), getHeight());
padding = Math.max(
Math.max(getPaddingBottom(), getPaddingTop()),
Math.max(getPaddingRight(), getPaddingLeft()));
maxSize -= padding * 2;
middle = maxSize / 2f;
pathMeasure = new PathMeasure();
PointF p1a = new PointF(middle, 0);
PointF p1b = getCheckRightPoint(maxSize);
firstPath = new Path();
firstPath.moveTo(p1a.x, p1a.y);
firstPath.lineTo(p1b.x, p1b.y);
pathMeasure.setPath(firstPath, false);
firstPathLength = pathMeasure.getLength();
PointF p2a = new PointF(middle, maxSize);
PointF p2b = getCheckMiddlePoint(maxSize);
secondPath = new Path();
secondPath.moveTo(p2a.x, p2a.y);
secondPath.lineTo(p2b.x, p2b.y);
pathMeasure.setPath(secondPath, false);
secondPathLength = pathMeasure.getLength();
PointF p3a = new PointF(0, middle);
PointF p3b = getCheckLeftPoint(maxSize);
thirdPath = new Path();
thirdPath.moveTo(p3a.x, p3a.y);
thirdPath.lineTo(p3b.x, p3b.y);
pathMeasure.setPath(thirdPath, false);
thirdPathLength = pathMeasure.getLength();
PointF p4a = new PointF(maxSize, middle);
fourPath = new Path();
fourPath.moveTo(p4a.x, p4a.y);
fourPath.lineTo(p2b.x, p2b.y);
pathMeasure.setPath(fourPath, false);
fourPathLength = pathMeasure.getLength();
paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(color);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeCap(Paint.Cap.SQUARE);
paint.setStrokeWidth(strokeWidth);
fromXY = new float[]{0f, 0f};
toXY = new float[]{0f, 0f};
}
示例8: buildBrokenLines
import android.graphics.PathMeasure; //导入方法依赖的package包/类
/**
* Build warped-lines according to the baselines, like the DiscretePathEffect.
*/
private void buildBrokenLines(Rect r) {
LinePath[] baseLines = new LinePath[mConfig.complexity];
buildBaselines(baseLines, r);
PathMeasure pmTemp = new PathMeasure();
for (int i = 0; i < mConfig.complexity; i++) {
lineRifts[i] = new LinePath();
lineRifts[i].moveTo(0, 0);
lineRifts[i].setEndPoint(baseLines[i].getEndPoint());
pmTemp.setPath(baseLines[i], false);
float length = pmTemp.getLength();
final int THRESHOLD = SEGMENT + SEGMENT / 2;
if (length > Utils.dp2px(THRESHOLD)) {
lineRifts[i].setStraight(false);
// First, line to the point at SEGMENT of baseline;
// Second, line to the random-point at (SEGMENT+SEGMENT/2) of baseline;
// So when we set the start-draw-length to SEGMENT and the paint style is "FILL",
// we can make the line become visible faster(exactly, the triangle)
float[] pos = new float[2];
pmTemp.getPosTan(Utils.dp2px(SEGMENT), pos, null);
lineRifts[i].lineTo(pos[0], pos[1]);
lineRifts[i].points.add(new Point((int)pos[0], (int)pos[1]));
int xRandom, yRandom;
int step = Utils.dp2px(THRESHOLD);
do{
pmTemp.getPosTan(step, pos, null);
// !!!
// Here determine the stroke width of lineRifts
xRandom = (int) (pos[0] + Utils.nextInt(-Utils.dp2px(3),Utils.dp2px(2)));
yRandom = (int) (pos[1] + Utils.nextInt(-Utils.dp2px(2),Utils.dp2px(3)));
lineRifts[i].lineTo(xRandom, yRandom);
lineRifts[i].points.add(new Point(xRandom, yRandom));
step += Utils.dp2px(SEGMENT);
} while (step < length);
lineRifts[i].lineToEnd();
} else {
// Too short, it's still a beeline, so we must warp it later {@warpStraightLines()},
// to make sure it is visible in "FILL" mode.
lineRifts[i] = baseLines[i];
lineRifts[i].setStraight(true);
}
lineRifts[i].points.add(lineRifts[i].getEndPoint());
}
}
示例9: PathObj
import android.graphics.PathMeasure; //导入方法依赖的package包/类
/**
* 初始化路径
*
* @param bitmap 绘制的图片
*/
public PathObj(Bitmap bitmap) {
this.bitmap = bitmap;
this.bitmapWidth = bitmap.getWidth();
this.bitmapHeight = bitmap.getHeight();
bitmapWidthDst = bitmapWidth;// + bitmapWidth/4;
bitmapHeightDst = bitmapHeight;// + bitmapHeight/4;
src = new Rect(0, 0, bitmapWidth, bitmapHeight);
dst = new Rect(0, 0, bitmapWidthDst / 2, bitmapHeightDst / 2);
paint = new Paint();
paint.setAntiAlias(true);
path = new Path();
pathMeasure = new PathMeasure();
int factor = 2;
int initX = (int) mContext.getResources().getDimension(R.dimen.heart_anim_init_x);
int initY = (int) mContext.getResources().getDimension(R.dimen.heart_anim_init_y);
int xRand = (int) mContext.getResources().getDimension(R.dimen.heart_anim_bezier_x_rand);
int animLengthRand = (int) mContext.getResources().getDimension(R.dimen.heart_anim_length_rand);
int bezierFactor = 6;
int animLength = (int) mContext.getResources().getDimension(R.dimen.heart_anim_length);
int xPointFactor = (int) mContext.getResources().getDimension(R.dimen.heart_anim_x_point_factor);
int x = mRandom.nextInt(xRand);
int x2 = mRandom.nextInt(xRand);
int y = getHeight() - initY;
int y2 = animLength * factor + mRandom.nextInt(animLengthRand);
factor = y2 / bezierFactor;
x = xPointFactor + x;
x2 = xPointFactor + x2;
int y3 = y - y2;
y2 = y - y2 / 2;
path.moveTo(initX, y);
path.cubicTo(initX, y - factor, x, y2 + factor, x, y2);
path.moveTo(x, y2);
path.cubicTo(x, y2 - factor, x2, y3 + factor, x2, y3);
pathMeasure.setPath(path, false);
length = (int) pathMeasure.getLength();
speed = mRandom.nextInt(1) + 1f;
}
示例10: getRestLength
import android.graphics.PathMeasure; //导入方法依赖的package包/类
private float getRestLength(Path path, float startD) {
Path tempPath = new Path();
PathMeasure pathMeasure = new PathMeasure(path, false);
pathMeasure.getSegment(startD, pathMeasure.getLength(), tempPath, true);
pathMeasure.setPath(tempPath, false);
return pathMeasure.getLength();
}