2

I want to show the image like pen while drawing on the canvas. It looks like i am drawing threw pen. And while i stop drawing, the image of pen should be hide.

Is it possible to do ? If yes then what should i have to do to make it ? Thanks.

Shreyash Mahajan
  • 23,386
  • 35
  • 116
  • 188
  • I think you have to use animation – Newts Nov 17 '11 at 10:59
  • I'm guessing that you want a canvas which the user can draw on to (like a painting app)? If so, you can just draw an image of a pen (onto the canvas) so that its point is where the user is pressing. But I think that'll be the least of your worries. – FunkTheMonk Nov 17 '11 at 11:00
  • @FunkTheMonk : I am using canvas to do paint. But i want is, While i am moving my hand on the canvas to draw, the image like pen is displayed on the point i am tauching the screen. And if i touch up then the image of pen is hide. – Shreyash Mahajan Nov 17 '11 at 11:05
  • Is there any code to do like this ? – Shreyash Mahajan Nov 17 '11 at 11:39
  • Yes its possible go through to given link [Saving canvas images][1] [1]: http://stackoverflow.com/questions/2174875/android-canvas-to-jpg – Tofeeq Ahmad Nov 19 '11 at 09:26

1 Answers1

1

yes take a bitmap in the canvas and draw it by specifying the coordinates

eg.

          int Down_yvalue=0;
          int Current_yvalue=0;
          Bitmap bmp1 = BitmapFactory.decodeResource(getResources(), R.drawable.face);
      canvas.drawBitmap(bmp1, Down_yvalue, Current_yvalue, new Paint());    

and ontouch event get the coordinates and redraw it by calling this method invalidate eg .

               public boolean onTouchEvent(MotionEvent event) {
               Down_yvalue=(int)event.getX();
               Current_yvalue=(int) event.getY();
               invalidate() ;
            }