0

So I have a PNG file which I am using as a custom brush in my app. As a motion event takes place, I keep redrawing it to give a brush effect. But if I drag too fast I miss pixels and some brushes look really bad - like the images are just drawn over each other.

Is there any way I can draw it in a drawpath mode instead?

The code below is my onDraw method. The mbitmapBrush variable has the PNG image file, and pos.a and pos.b are the current motion event 'x' and 'y' coordinates.

 @Override
    protected void onDraw(Canvas canvas) {
        Paint paint=mPaint;
        canvas.drawColor(0xFFAAAAAA);
mCM.set(new float[]{1f, 1f, 1f, 0f, 1f,
    0f, 1f, 3f, 0f, 4f,
    1f, 4f, 1f, 1f, 0f,
    1f, 0f, 0f, 1f, 0f });
ColorMatrixColorFilter cm3=new ColorMatrixColorFilter(mCM);

paint.setColorFilter(cm3);

        canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
        for (Vector2 pos : mPositions) {

            canvas.drawBitmap(mBitmapBrush, pos.a, pos.b, paint);
            //canvas.drawCircle(pos.a, pos.b, 7, mPaint);
        }

        //canvas.drawBitmap(mBitmapBrush, clickX, clickY, null);
        //canvas.drawPath(mPath, mPaint);

    invalidate();
    }
Cylindric
  • 5,858
  • 5
  • 46
  • 68
  • Have you considered using a custom `SurfaceView` and calling the `draw()` method manually from a loop? That way you have more control over the rate at which it draws. – Jimbali Jun 27 '12 at 13:54
  • Yup trying that, also will using `getHistoricalX` and `getHistoricalY` help in making more drawing points. Under what condition can i run the loop to make it draw more points? – user1472707 Jun 27 '12 at 15:44
  • If you are updating the position every time `onTouch()` is called then you are already getting the best temporal resolution possible. I would create a thread and have a while loop that calls `mySurface.draw()` and then sleeps for say 20 milliseconds each time it loops. Alternatively you could just call `draw()` every time `onTouch()` is called. – Jimbali Jun 27 '12 at 17:25
  • Hey, im new to the Graphics API, i Got the manual calling of the method, working alot smoother but not in the surface view. could you please give me a small snippet of code, just something to show the working of surfaceview. Thanks – user1472707 Jun 28 '12 at 16:45
  • 1
    This should help you get to grips with extending `SurfaceView`: http://www.gamingfordroids.com/2011/09/drawing-with-surfaceview.html – Jimbali Jun 29 '12 at 09:15

0 Answers0