android 结合压感绘制笔迹的问题

 

private float PRESS_LEVEL = 16.5f;

info: class PathInfo{ Path path; Rect rect; int color; float press; public PathInfo(Path pth, Rect rc, float prss){ path = pth; rect = new Rect(rc); color = GlobalSetting.mScriptColor; press = prss; } public PathInfo(Path pth, int left, int top, int right, int bottom){ path = pth; rect = new Rect(left, top, right, bottom); } } paint初始化: List mPathInfo = new ArrayList(); mPath = new Path(); mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeWidth(GlobalSetting.mScriptWidth); mPaint.setColor(...); onDraw绘制: PathInfo pathInfo; for (int i = 0; i < mPathInfo.size(); i++){ pathInfo = mPathInfo.get(i); if (Rect.intersects(r, pathInfo.rect)){ mPaint.setColor(pathInfo.color); //press mPaint.setStrokeWidth(pathInfo.press); //press over } canvas.drawPath(pathInfo.path, mPaint); } down: mCurX = (int)event.getX(); mCurY = (int)event.getY(); mPrevX = mCurX; mPrevY = mCurY; //press float pressD = event.getPressure(); float width = getEventPress(pressD); mPaint.setStrokeWidth(width); mPath = new Path(); mPath.moveTo(mCurX, mCurY); PathInfo pathInfoH = new PathInfo(mPath, mRect, width); mPathInfo.add(pathInfoH); mPrePress = width; move: for (i=0; i

实现apidemos中的笔迹绘制,但是压感的公式需要调整。

你可能感兴趣的:(android 结合压感绘制笔迹的问题)