Drawing rainbow paint on canvas android

I am working on several finger drawing applications. My requirement is that I need to paint with multicolor paint. I have seen several apps on the play store that make this concept very fluid

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

Here is the code for the view draw class

    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);

    }

      

With the above code, I can draw points with many colors. But the problem comes when I used t draw fast. Then it misses some points and the drawing is not smooth.

Another big problem is that drawing is slow. How to make a drawing faster and smoother.

Genius guidance required!

+3
android android-canvas paint


source to share


No one has answered this question yet

Check out similar questions:

3606
Close / hide Android soft keyboard
3295
Why is the Android emulator so slow? How can we speed up the development of an Android emulator?
3288
Correct use cases for Android UserManager.isUserAGoat ()?
2609
Is there a unique identifier for an Android device?
2510
How to persist android activity state by persisting instance state?
2097
Is there a way to run Python on Android?
1858
"Debug certificate expired" error in Android Eclipse plugins
1844
What is "Context" on Android?
685
Android separator / line separator in layout?
0
Undo / Redo not working in android Canvas



All Articles
Loading...
X
Show
Funny
Dev
Pics