我有一个小绘图应用程序,想使用“复杂”形状作为画笔,即星形。使用简单的画笔绘图已经可以使用以下代码:
remotePath.reset();
remotePath.moveTo(start_x, start_y);
float dx = Math.abs(end_x - start_x);
float dy = Math.abs(end_y - start_y);
if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
remotePath.quadTo(start_x, start_y, (end_x + start_x) / 2, (end_y + start_y) / 2);
}
remotePath.lineTo(end_x, end_y);
// commit the path to our offscreen
mCanvas.drawPath(remotePath, remotePaint);
// kill this so we don't double draw
remotePath.reset();
invalidate();
我基本上想要使用此位图的相同功能:
Bitmap myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.brush_star);
我目前的解决方案是使用点(坐标)列表来绘制位图。该解决方案的问题在于它仅在给定点绘制位图,导致每个绘制的位图之间存在间隙。我宁愿在用简单的画笔绘制时获得一条平滑的线条,中间没有任何间隙。
位图绘制的当前代码:
protected void onDraw(Canvas canvas) {
// Make canvas white
canvas.drawColor(Color.WHITE);
// Paintable area
canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
canvas.drawPath(mPath, mPaint);
for (Point point : points) {
canvas.drawBitmap(complexBrush, point.x, point.y, p);
}
}
最好的方法是什么?谢谢你的帮助!