在画布上绘制彩虹油漆android

时间:2014-12-29 19:14:55

标签: android android-canvas paint

我正在研究多个手指绘图应用。我的要求是我需要绘制彩虹涂料(多色涂料)。我在Play商店看到很少有能够非常顺利地完成这个概念的应用程序

https://play.google.com/store/apps/details?id=com.doodlejoy.studio.doodleworld

这是绘制视图类的代码

    int[] mColors = new int[] { 0xFFFF0000, 0xFFFF00FF, 0xFF0000FF, 0xFF00FFFF,
                0xFF00FF00, 0xFFFFFF00, 0xFFFF0000, Color.MAGENTA, Color.CYAN };

@Override
public boolean onTouchEvent(MotionEvent event) {

    int pointerCount = event.getPointerCount();
    int cappedPointerCount = pointerCount > MAX_FINGERS ? MAX_FINGERS
            : pointerCount;
    int actionIndex = event.getActionIndex();
    int action = event.getActionMasked();
    int id = event.getPointerId(actionIndex);

    if ((action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_POINTER_DOWN)
            && id < MAX_FINGERS) {

        mFingerPaths[id] = new Path();
        mFingerPaths[id].moveTo(event.getX(actionIndex),
                event.getY(actionIndex));




    } 

    else if ((action == MotionEvent.ACTION_POINTER_UP || action == MotionEvent.ACTION_UP)
            && id < MAX_FINGERS) {

        mFingerPaths[id].setLastPoint(event.getX(actionIndex),
                event.getY(actionIndex));

        cor.setStrokeWidth(brushSize);
        // cor.setColor(isSetRanbow ?
        // mColors[random.nextInt(mColors.length)]
        // : paintColor);

        mFingerPaths[id].computeBounds(mPathBounds, true);

        mCompletedPaths.add(new PaintItem(mFingerPaths[id], brushSize, cor
                .getColor()));

        invalidate();
        mFingerPaths[id] = null;




    for (int i = 0; i < cappedPointerCount; i++) {
        if (mFingerPaths[i] != null) {
            int index = event.findPointerIndex(i);
            if (isSetRanbow) {
                cor.setColor(mColors[random.nextInt(mColors.length)]);
            }
            mFingerPaths[i].lineTo(event.getX(index), event.getY(index));

            mFingerPaths[i].computeBounds(mPathBounds, true);
            if (isSetRanbow) {
                 drawCanvas.drawPoint(event.getX(index),
                 event.getY(index), cor);

            } else {
                drawCanvas.drawPath(mFingerPaths[i], cor);
            }

            invalidate();
        }
    } 



    return true;
} 

@Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        canvas.drawBitmap(canvasBitmap, 0, 0, mPaint);
        if (mPath != null)
            canvas.drawPath(mPath, mPaint);

    }

使用上面的代码,我可以绘制多种颜色的点。但是当我快速使用t画时会出现问题。然后它跳过一些点并且绘图不顺畅。

另一个大问题是绘图很慢。如何使绘图更快更顺畅。

需要天才指南!!

0 个答案:

没有答案