Shreyash Mahajan
Shreyash Mahajan

Reputation: 23596

Is it possible to show image while i am drawing on the canvas?

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.

Upvotes: 2

Views: 209

Answers (1)

Harsh Dev Chandel
Harsh Dev Chandel

Reputation: 763

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

Upvotes: 1

Related Questions