void drawOneWord(Canvas canvas, float fScale) { ArrayList pplist = pathDrawing.getPointList(); for (int i = 0; i < pplist.size(); i++) { drawOneStroke(canvas, i, fScale); } pathDrawing.ResetPointList(); nWordCount++; }
public void fingerUp(float x, float y, Canvas canvas) { // 设置光标位置 if (GlobalVariables.getInstance().isMoveCursor()) { doXY((int) x, (int) y); pathDrawing.resetLimit(); return; } pathDrawing.fingerUp(x, y, canvasSrc); startTimer(); setCanvasBuffer(canvas); }
public void fingerMove(float x, float y, Canvas canvas) { float dx = x - x1; float dy = y - y1; if (Math.abs(dx) > 15 || Math.abs(dy) > 15) { GlobalVariables.getInstance().setMoveCursor(false); pathDrawing.fingerMove(x, y, canvas); l = pathDrawing.getLeftLimit(); r = pathDrawing.getRightLimit(); t = pathDrawing.getTopLimit(); b = pathDrawing.getBottomLimit(); } }
public void draw(Canvas canvas) { if (canvas != null) { canvas.drawBitmap(bitmapDst, 0.0f, 0.0f, null); drawWordLines(canvas); pathDrawing.draw(canvas); } }
public void fingerDown(float x, float y, Canvas canvas) { x1 = x; y1 = y; pathDrawing.fingerDown(x, y, canvas); if ((l == 0) && (r == 0) && (t == 0) && (b == 0)) { l = (int) x; t = (int) y; } stopTimer(); }
void CopyDrawImage(Canvas canvas) { float fScale = 0.0f; try { fScale = (nItemHeight - 5) * 100 / (b - t); fScale /= 100; if ((r - l) > 0) { sHWRate = (b - t) * 1000 / (r - l); sHWRate /= 1000; } if ((sHWRate < 0.25f) && ((b - t) < 50)) fScale = 0.5f; if (r - l < 25 && b - t < 25) { fScale = 1.0f; } } catch (Exception e) { e.printStackTrace(); } int nWidth = (int) ((r - l) * fScale + 5); int nNextStartX = 0; // nNextStartX :预期的结束点,即下一个字的开始点 nNextStartX = nstartx + nWidth; if (nNextStartX > GlobalVariables.screenWidth) { nLineCount++; nstarty += 40; nstartx = 5; nNextStartX = nstartx + nWidth; } pListWordSection.add(new WordSection(this, nstartx, nLineCount, nWidth)); drawOneWord(canvas, fScale); nstartx = nNextStartX; l = t = r = b = 0; pathDrawing.resetLimit(); pathDrawing.ResetPointList(); bitmapSrc.eraseColor(0); draw(canvas); view.invalidate(); }
void drawOneStroke(Canvas canvas, int nStroke, float fScale) { ArrayList pplist = pathDrawing.getPointList(); List<PathLine.point> list = (List) pplist.get(nStroke); path.reset(); point p = new point(((PathLine.point) list.get(0)).x, ((PathLine.point) list.get(0)).y); p.x = (p.x - (float) l); p.y = (p.y - (float) t); if (p.x < 0x0) { Log.d("error", "posx exception"); } if (p.y < 0) { Log.d("error", "posy exception"); } p.x = (p.x * fScale); p.y = (p.y * fScale); if (sHWRate < 0.1f) { p.y = 10.0f; } p.x = (p.x + (float) nstartx); p.y = (p.y + (float) nstarty); path.moveTo(p.x, p.y); float mX = p.x; float mY = p.y; for (int i = 0x1; i < list.size(); i = i + 0x1) { p.setXY( (((PathLine.point) list.get(i)).x - (float) l), (((PathLine.point) list.get(i)).y - (float) t)); p.x = (p.x * fScale); p.y = (p.y * fScale); if (sHWRate < 0.1f) { p.y = 10.0f; } if (p.x < 0x0) { Log.d("error", "pos exception"); } if (p.y < 0) { Log.d("error", "posy exception"); } p.x = (p.x + (float) nstartx); p.y = (p.y + (float) nstarty); path.quadTo(mX, mY, ((p.x + mX) / 2.0f), ((p.y + mY) / 2.0f)); mX = p.x; mY = p.y; } try { canvas.drawPath(path, thinPen); return; } catch (Exception e) { e.printStackTrace(); } }
public HandDraw(View v) { view = v; try { bitmapSrc = Bitmap.createBitmap( GlobalVariables.screenWidth, GlobalVariables.canvasHeigh, Bitmap.Config.ARGB_4444); bitmapSrc.eraseColor(0x0); canvasSrc = new Canvas(bitmapSrc); bitmapDst = Bitmap.createBitmap( GlobalVariables.screenWidth, GlobalVariables.canvasHeigh, Bitmap.Config.ARGB_4444); bitmapDst.eraseColor(0x0); canvasDst = new Canvas(bitmapDst); DrawingFactory factory = new DrawingFactory(); pathDrawing = (PathLine) factory.createDrawing(DrawingId.DRAWING_PATHLINE, null); Paint paint = new Paint(); paint = Brush.getPen(); pathDrawing.setPen(paint); canvasSrc.setDrawFilter(new PaintFlagsDrawFilter(0x0, 0x3)); } catch (OutOfMemoryError e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } // 笔迹颜色 path = new Path(); int colll = Brush.getPen().getColor(); thinPen.setColor(colll); thinPen.setStrokeWidth(1.5f); thinPen.setAntiAlias(true); thinPen.setDither(true); thinPen.setStyle(Paint.Style.STROKE); thinPen.setStrokeJoin(Paint.Join.ROUND); thinPen.setStrokeCap(Paint.Cap.ROUND); }