Draw on canvas (SurfaceView)


Last Updated:

  1. hollowback

    hollowback Member This Topic's Starter

    Joined:
    Nov 12, 2009
    Messages:
    5
    Likes Received:
    0
    Hi, I'm trying to do easy app for draw on screen. I followed the tutorial on Graphics | Android Developers.
    In my onTouchEvent method I have:
    Code (Text):
    1. _canvas = holder.lockCanvas();
    2.         if (event.getAction() == MotionEvent.ACTION_DOWN) {
    3.             _path = new Path();
    4.             _path.moveTo(event.getX(), event.getY());
    5.             _path.lineTo(event.getX(), event.getY());
    6.         } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
    7.             _path.lineTo(event.getX(), event.getY());          
    8.             _canvas.drawPath(_path, mPaint);
    9.             _path = new Path();
    10.             _path.moveTo(event.getX(), event.getY());
    11.         } else if (event.getAction() == MotionEvent.ACTION_UP) {
    12.             _path.lineTo(event.getX(), event.getY());
    13.             _canvas.drawPath(_path, mPaint);
    14.         }      
    15.         holder.unlockCanvasAndPost(_canvas);
    16.  
    But when I draw, it shows something like that:
    [​IMG]
    so I draw another lines and image changes to
    [​IMG]

    In constructor of my MySurface class (which extends SurfaceView and implements SurfaceHolder.Callback) i set up holder variable:
    Code (Text):
    1.         holder = getHolder();
    2.         holder.addCallback(this);
    Does anybody know what is wrong?
     

    Advertisement
  2. Macrex

    Macrex New Member

    Joined:
    Apr 4, 2012
    Messages:
    1
    Likes Received:
    0
    man, I'm having the same problem.
    you managed to solve?

    thank you
     
  3. jonbonazza

    jonbonazza Well-Known Member

    Joined:
    Jul 13, 2010
    Messages:
    1,934
    Likes Received:
    458
    Have you tried running it on a physical device? Anything related to graphics tends to either work poorly or simply not work at all on the AVD.
     

Share This Page

Loading...