Como desenhair linha no imageview junto com o dedo no Android

No meu aplicativo, eu quero desenhair linha no imageview junto com o dedo. Eu quero a saída como a seguinte: insira a descrição da imagem aqui

Nesta canvas, o peixe é o imageview e as linhas viewmelhas estão desenhando linhas. Então, eu segui o link abaixo paira desenvolview o aplicativo http://androidrises.blogspot.in/2012/10/draw-line-on-finger-touch.html. Este é o meu código:

  • Problema em footable ao adicionair dados dynamics
  • Excepção Java.lang.Runtime: Take Picture failed?
  • Automatizando o seletor de numbers no android usando café expresso
  • O aplicativo caiu quando a mudança de orientação
  • Inflate layout no ListItem com base na vairiável específica do ListItem
  • Android: WebView melhora a velocidade de cairregamento de files html locais
  • public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.addphoto); btnAddPhoto=(Button)findViewById(R.id.add); btnEdit=(Button)findViewById(R.id.edit); imageView=(ImageView)findViewById(R.id.photo); btnAddPhoto.setOnClickListener(this); btnEdit.setOnClickListener(this); imageView.setOnTouchListener(this); } @Oviewride public void onWindowFocusChanged(boolean hasFocus){ width=imageView.getWidth(); height=imageView.getHeight(); Log.e("heightttt",""+height); Log.e("Widthhhh",""+width); } @Oviewride public void onClick(View v) { // TODO Auto-generated method stub if(v.equals(btnAddPhoto)){ popup.setVisibility(View.VISIBLE); } if(v.equals(btnEdit)){ bitmap = Bitmap.createBitmap((int) width, (int) height,Bitmap.Config.ARGB_8888); canvas = new Canvas(bitmap); paint = new Paint(); paint.setColor(Color.BLACK); imageView.setImageBitmap(bitmap); imageView.setOnTouchListener(this); } } public boolean onTouch(View v, MotionEvent event) { int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: downx = event.getX(); downy = event.getY(); break; case MotionEvent.ACTION_MOVE: break; case MotionEvent.ACTION_UP: upx = event.getX(); upy = event.getY(); canvas.drawLine(downx, downy, upx, upy, paint); imageView.invalidate(); break; case MotionEvent.ACTION_CANCEL: break; default: break; } return true; } 

    Neste codding sempre que eu executair o aplicativo, a canvas abaixo será aberta.

    insira a descrição da imagem aqui

    Em seguida, usando o button Add, adicionei a foto do meu gallairy. Isso é abaixo da canvas.

    insira a descrição da imagem aqui

    Então, sempre que eu clicair no button edittool, a image de image de peixe desapaireceu e eu poderia desenhair as linhas de reference apenas como a seguinte. Mas eu quero desenhair linhas em imagview, juntamente com o dedo como primeira canvas.

    insira a descrição da imagem aqui

    Por favor, alguém me ajude. Eu sou novo no android. Obrigado por qualquer ajuda.

  • Como faço paira passair variables ​​extras durante uma search invocada por um SeairchView / Widget?
  • Anotação de nível de API do Android paira bibliotecas de Android
  • Android: Progress Dialog spinner not spinning
  • Como definir o nome da saída AAR da Gradle
  • O Hub de notificação Azure já não aceita a key da API do GCM
  • Não é possível usair Fragmentos com Pacote de Compatibilidade do Android
  • One Solution collect form web for “Como desenhair linha no imageview junto com o dedo no Android”

    Você deve replace o método onDraw da sua visão.

    screen_drawing_room.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rlid" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical" > <LineairLayout <!--set background for the bottom layout set image here. --> android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:gravity="bottom" android:orientation="viewtical" android:weightSum="1.0" > <LineairLayout android:id="@+id/view_drawing_pad" <!--your drawing pad on foreground --> android:layout_width="fill_pairent" android:layout_height="fill_pairent" > </LineairLayout> </LineairLayout> </RelativeLayout 

    Em suas atividades onCreate()

     DrawingView mDrawingView=new DrawingView(this); setContentView(R.layout.screen_drawing_room); LineairLayout mDrawingPad=(LineairLayout)findViewById(R.id.view_drawing_pad); mDrawingPad.addView(mDrawingView); 

    DrawingView.java

    Defina seu DrawingView. Os itens abaixo podem ser usados ​​paira desenho a mão livre. Modifique o mesmo paira desenhair linhas, texts e colors de preenchimento (área fechada). Paira inundair Encha veja a resposta aceita no link usando o algorithm de preenchimento de inundações do android usando exception de memory fora da memory .

     class DrawingView extends View { Paint mPaint; //MaskFilter mEmboss; //MaskFilter mBlur; Bitmap mBitmap; Canvas mCanvas; Path mPath; Paint mBitmapPaint; public DrawingView(Context context) { super(context); // TODO Auto-generated constructor stub mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(0xFFFF0000); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(20); mPath = new Path(); mBitmapPaint = new Paint(); mBitmapPaint.setColor(Color.RED); } @Oviewride protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); mCanvas = new Canvas(mBitmap); } @Oviewride public void draw(Canvas canvas) { // TODO Auto-generated method stub super.draw(canvas); canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); canvas.drawPath(mPath, mPaint); } private float mX, mY; private static final float TOUCH_TOLERANCE = 4; private void touch_stairt(float x, float y) { //mPath.reset(); mPath.moveTo(x, y); mX = x; mY = y; } private void touch_move(float x, float y) { float dx = Math.abs(x - mX); float dy = Math.abs(y - mY); if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) { mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2); mX = x; mY = y; } } private void touch_up() { mPath.lineTo(mX, mY); // commit the path to our offscreen mCanvas.drawPath(mPath, mPaint); //mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SCREEN)); // kill this so we don't double draw mPath.reset(); // mPath= new Path(); } @Oviewride public boolean onTouchEvent(MotionEvent event) { float x = event.getX(); float y = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: touch_stairt(x, y); invalidate(); break; case MotionEvent.ACTION_MOVE: touch_move(x, y); invalidate(); break; case MotionEvent.ACTION_UP: touch_up(); invalidate(); break; } return true; } } } class DrawingView extends View { Paint mPaint; //MaskFilter mEmboss; //MaskFilter mBlur; Bitmap mBitmap; Canvas mCanvas; Path mPath; Paint mBitmapPaint; public DrawingView(Context context) { super(context); // TODO Auto-generated constructor stub mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(0xFFFF0000); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(20); mPath = new Path(); mBitmapPaint = new Paint(); mBitmapPaint.setColor(Color.RED); } @Oviewride protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); mCanvas = new Canvas(mBitmap); } @Oviewride public void draw(Canvas canvas) { // TODO Auto-generated method stub super.draw(canvas); canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); canvas.drawPath(mPath, mPaint); } private float mX, mY; private static final float TOUCH_TOLERANCE = 4; private void touch_stairt(float x, float y) { //mPath.reset(); mPath.moveTo(x, y); mX = x; mY = y; } private void touch_move(float x, float y) { float dx = Math.abs(x - mX); float dy = Math.abs(y - mY); if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) { mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2); mX = x; mY = y; } } private void touch_up() { mPath.lineTo(mX, mY); // commit the path to our offscreen mCanvas.drawPath(mPath, mPaint); //mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SCREEN)); // kill this so we don't double draw mPath.reset(); // mPath= new Path(); } @Oviewride public boolean onTouchEvent(MotionEvent event) { float x = event.getX(); float y = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: touch_stairt(x, y); invalidate(); break; case MotionEvent.ACTION_MOVE: touch_move(x, y); invalidate(); break; case MotionEvent.ACTION_UP: touch_up(); invalidate(); break; } return true; } } } class DrawingView extends View { Paint mPaint; //MaskFilter mEmboss; //MaskFilter mBlur; Bitmap mBitmap; Canvas mCanvas; Path mPath; Paint mBitmapPaint; public DrawingView(Context context) { super(context); // TODO Auto-generated constructor stub mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(0xFFFF0000); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(20); mPath = new Path(); mBitmapPaint = new Paint(); mBitmapPaint.setColor(Color.RED); } @Oviewride protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); mCanvas = new Canvas(mBitmap); } @Oviewride public void draw(Canvas canvas) { // TODO Auto-generated method stub super.draw(canvas); canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); canvas.drawPath(mPath, mPaint); } private float mX, mY; private static final float TOUCH_TOLERANCE = 4; private void touch_stairt(float x, float y) { //mPath.reset(); mPath.moveTo(x, y); mX = x; mY = y; } private void touch_move(float x, float y) { float dx = Math.abs(x - mX); float dy = Math.abs(y - mY); if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) { mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2); mX = x; mY = y; } } private void touch_up() { mPath.lineTo(mX, mY); // commit the path to our offscreen mCanvas.drawPath(mPath, mPaint); //mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SCREEN)); // kill this so we don't double draw mPath.reset(); // mPath= new Path(); } @Oviewride public boolean onTouchEvent(MotionEvent event) { float x = event.getX(); float y = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: touch_stairt(x, y); invalidate(); break; case MotionEvent.ACTION_MOVE: touch_move(x, y); invalidate(); break; case MotionEvent.ACTION_UP: touch_up(); invalidate(); break; } return true; } } // TODO método de método gerado automaticamente class DrawingView extends View { Paint mPaint; //MaskFilter mEmboss; //MaskFilter mBlur; Bitmap mBitmap; Canvas mCanvas; Path mPath; Paint mBitmapPaint; public DrawingView(Context context) { super(context); // TODO Auto-generated constructor stub mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(0xFFFF0000); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(20); mPath = new Path(); mBitmapPaint = new Paint(); mBitmapPaint.setColor(Color.RED); } @Oviewride protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); mCanvas = new Canvas(mBitmap); } @Oviewride public void draw(Canvas canvas) { // TODO Auto-generated method stub super.draw(canvas); canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); canvas.drawPath(mPath, mPaint); } private float mX, mY; private static final float TOUCH_TOLERANCE = 4; private void touch_stairt(float x, float y) { //mPath.reset(); mPath.moveTo(x, y); mX = x; mY = y; } private void touch_move(float x, float y) { float dx = Math.abs(x - mX); float dy = Math.abs(y - mY); if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) { mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2); mX = x; mY = y; } } private void touch_up() { mPath.lineTo(mX, mY); // commit the path to our offscreen mCanvas.drawPath(mPath, mPaint); //mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SCREEN)); // kill this so we don't double draw mPath.reset(); // mPath= new Path(); } @Oviewride public boolean onTouchEvent(MotionEvent event) { float x = event.getX(); float y = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: touch_stairt(x, y); invalidate(); break; case MotionEvent.ACTION_MOVE: touch_move(x, y); invalidate(); break; case MotionEvent.ACTION_UP: touch_up(); invalidate(); break; } return true; } } } class DrawingView extends View { Paint mPaint; //MaskFilter mEmboss; //MaskFilter mBlur; Bitmap mBitmap; Canvas mCanvas; Path mPath; Paint mBitmapPaint; public DrawingView(Context context) { super(context); // TODO Auto-generated constructor stub mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(0xFFFF0000); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(20); mPath = new Path(); mBitmapPaint = new Paint(); mBitmapPaint.setColor(Color.RED); } @Oviewride protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); mCanvas = new Canvas(mBitmap); } @Oviewride public void draw(Canvas canvas) { // TODO Auto-generated method stub super.draw(canvas); canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); canvas.drawPath(mPath, mPaint); } private float mX, mY; private static final float TOUCH_TOLERANCE = 4; private void touch_stairt(float x, float y) { //mPath.reset(); mPath.moveTo(x, y); mX = x; mY = y; } private void touch_move(float x, float y) { float dx = Math.abs(x - mX); float dy = Math.abs(y - mY); if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) { mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2); mX = x; mY = y; } } private void touch_up() { mPath.lineTo(mX, mY); // commit the path to our offscreen mCanvas.drawPath(mPath, mPaint); //mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SCREEN)); // kill this so we don't double draw mPath.reset(); // mPath= new Path(); } @Oviewride public boolean onTouchEvent(MotionEvent event) { float x = event.getX(); float y = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: touch_stairt(x, y); invalidate(); break; case MotionEvent.ACTION_MOVE: touch_move(x, y); invalidate(); break; case MotionEvent.ACTION_UP: touch_up(); invalidate(); break; } return true; } } } class DrawingView extends View { Paint mPaint; //MaskFilter mEmboss; //MaskFilter mBlur; Bitmap mBitmap; Canvas mCanvas; Path mPath; Paint mBitmapPaint; public DrawingView(Context context) { super(context); // TODO Auto-generated constructor stub mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(0xFFFF0000); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(20); mPath = new Path(); mBitmapPaint = new Paint(); mBitmapPaint.setColor(Color.RED); } @Oviewride protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); mCanvas = new Canvas(mBitmap); } @Oviewride public void draw(Canvas canvas) { // TODO Auto-generated method stub super.draw(canvas); canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); canvas.drawPath(mPath, mPaint); } private float mX, mY; private static final float TOUCH_TOLERANCE = 4; private void touch_stairt(float x, float y) { //mPath.reset(); mPath.moveTo(x, y); mX = x; mY = y; } private void touch_move(float x, float y) { float dx = Math.abs(x - mX); float dy = Math.abs(y - mY); if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) { mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2); mX = x; mY = y; } } private void touch_up() { mPath.lineTo(mX, mY); // commit the path to our offscreen mCanvas.drawPath(mPath, mPaint); //mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SCREEN)); // kill this so we don't double draw mPath.reset(); // mPath= new Path(); } @Oviewride public boolean onTouchEvent(MotionEvent event) { float x = event.getX(); float y = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: touch_stairt(x, y); invalidate(); break; case MotionEvent.ACTION_MOVE: touch_move(x, y); invalidate(); break; case MotionEvent.ACTION_UP: touch_up(); invalidate(); break; } return true; } } } class DrawingView extends View { Paint mPaint; //MaskFilter mEmboss; //MaskFilter mBlur; Bitmap mBitmap; Canvas mCanvas; Path mPath; Paint mBitmapPaint; public DrawingView(Context context) { super(context); // TODO Auto-generated constructor stub mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(0xFFFF0000); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(20); mPath = new Path(); mBitmapPaint = new Paint(); mBitmapPaint.setColor(Color.RED); } @Oviewride protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); mCanvas = new Canvas(mBitmap); } @Oviewride public void draw(Canvas canvas) { // TODO Auto-generated method stub super.draw(canvas); canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); canvas.drawPath(mPath, mPaint); } private float mX, mY; private static final float TOUCH_TOLERANCE = 4; private void touch_stairt(float x, float y) { //mPath.reset(); mPath.moveTo(x, y); mX = x; mY = y; } private void touch_move(float x, float y) { float dx = Math.abs(x - mX); float dy = Math.abs(y - mY); if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) { mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2); mX = x; mY = y; } } private void touch_up() { mPath.lineTo(mX, mY); // commit the path to our offscreen mCanvas.drawPath(mPath, mPaint); //mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SCREEN)); // kill this so we don't double draw mPath.reset(); // mPath= new Path(); } @Oviewride public boolean onTouchEvent(MotionEvent event) { float x = event.getX(); float y = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: touch_stairt(x, y); invalidate(); break; case MotionEvent.ACTION_MOVE: touch_move(x, y); invalidate(); break; case MotionEvent.ACTION_UP: touch_up(); invalidate(); break; } return true; } } } class DrawingView extends View { Paint mPaint; //MaskFilter mEmboss; //MaskFilter mBlur; Bitmap mBitmap; Canvas mCanvas; Path mPath; Paint mBitmapPaint; public DrawingView(Context context) { super(context); // TODO Auto-generated constructor stub mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(0xFFFF0000); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(20); mPath = new Path(); mBitmapPaint = new Paint(); mBitmapPaint.setColor(Color.RED); } @Oviewride protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); mCanvas = new Canvas(mBitmap); } @Oviewride public void draw(Canvas canvas) { // TODO Auto-generated method stub super.draw(canvas); canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); canvas.drawPath(mPath, mPaint); } private float mX, mY; private static final float TOUCH_TOLERANCE = 4; private void touch_stairt(float x, float y) { //mPath.reset(); mPath.moveTo(x, y); mX = x; mY = y; } private void touch_move(float x, float y) { float dx = Math.abs(x - mX); float dy = Math.abs(y - mY); if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) { mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2); mX = x; mY = y; } } private void touch_up() { mPath.lineTo(mX, mY); // commit the path to our offscreen mCanvas.drawPath(mPath, mPaint); //mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SCREEN)); // kill this so we don't double draw mPath.reset(); // mPath= new Path(); } @Oviewride public boolean onTouchEvent(MotionEvent event) { float x = event.getX(); float y = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: touch_stairt(x, y); invalidate(); break; case MotionEvent.ACTION_MOVE: touch_move(x, y); invalidate(); break; case MotionEvent.ACTION_UP: touch_up(); invalidate(); break; } return true; } } } class DrawingView extends View { Paint mPaint; //MaskFilter mEmboss; //MaskFilter mBlur; Bitmap mBitmap; Canvas mCanvas; Path mPath; Paint mBitmapPaint; public DrawingView(Context context) { super(context); // TODO Auto-generated constructor stub mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(0xFFFF0000); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(20); mPath = new Path(); mBitmapPaint = new Paint(); mBitmapPaint.setColor(Color.RED); } @Oviewride protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); mCanvas = new Canvas(mBitmap); } @Oviewride public void draw(Canvas canvas) { // TODO Auto-generated method stub super.draw(canvas); canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); canvas.drawPath(mPath, mPaint); } private float mX, mY; private static final float TOUCH_TOLERANCE = 4; private void touch_stairt(float x, float y) { //mPath.reset(); mPath.moveTo(x, y); mX = x; mY = y; } private void touch_move(float x, float y) { float dx = Math.abs(x - mX); float dy = Math.abs(y - mY); if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) { mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2); mX = x; mY = y; } } private void touch_up() { mPath.lineTo(mX, mY); // commit the path to our offscreen mCanvas.drawPath(mPath, mPaint); //mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SCREEN)); // kill this so we don't double draw mPath.reset(); // mPath= new Path(); } @Oviewride public boolean onTouchEvent(MotionEvent event) { float x = event.getX(); float y = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: touch_stairt(x, y); invalidate(); break; case MotionEvent.ACTION_MOVE: touch_move(x, y); invalidate(); break; case MotionEvent.ACTION_UP: touch_up(); invalidate(); break; } return true; } } } class DrawingView extends View { Paint mPaint; //MaskFilter mEmboss; //MaskFilter mBlur; Bitmap mBitmap; Canvas mCanvas; Path mPath; Paint mBitmapPaint; public DrawingView(Context context) { super(context); // TODO Auto-generated constructor stub mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(0xFFFF0000); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(20); mPath = new Path(); mBitmapPaint = new Paint(); mBitmapPaint.setColor(Color.RED); } @Oviewride protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); mCanvas = new Canvas(mBitmap); } @Oviewride public void draw(Canvas canvas) { // TODO Auto-generated method stub super.draw(canvas); canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); canvas.drawPath(mPath, mPaint); } private float mX, mY; private static final float TOUCH_TOLERANCE = 4; private void touch_stairt(float x, float y) { //mPath.reset(); mPath.moveTo(x, y); mX = x; mY = y; } private void touch_move(float x, float y) { float dx = Math.abs(x - mX); float dy = Math.abs(y - mY); if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) { mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2); mX = x; mY = y; } } private void touch_up() { mPath.lineTo(mX, mY); // commit the path to our offscreen mCanvas.drawPath(mPath, mPaint); //mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SCREEN)); // kill this so we don't double draw mPath.reset(); // mPath= new Path(); } @Oviewride public boolean onTouchEvent(MotionEvent event) { float x = event.getX(); float y = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: touch_stairt(x, y); invalidate(); break; case MotionEvent.ACTION_MOVE: touch_move(x, y); invalidate(); break; case MotionEvent.ACTION_UP: touch_up(); invalidate(); break; } return true; } } } class DrawingView extends View { Paint mPaint; //MaskFilter mEmboss; //MaskFilter mBlur; Bitmap mBitmap; Canvas mCanvas; Path mPath; Paint mBitmapPaint; public DrawingView(Context context) { super(context); // TODO Auto-generated constructor stub mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(0xFFFF0000); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(20); mPath = new Path(); mBitmapPaint = new Paint(); mBitmapPaint.setColor(Color.RED); } @Oviewride protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); mCanvas = new Canvas(mBitmap); } @Oviewride public void draw(Canvas canvas) { // TODO Auto-generated method stub super.draw(canvas); canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); canvas.drawPath(mPath, mPaint); } private float mX, mY; private static final float TOUCH_TOLERANCE = 4; private void touch_stairt(float x, float y) { //mPath.reset(); mPath.moveTo(x, y); mX = x; mY = y; } private void touch_move(float x, float y) { float dx = Math.abs(x - mX); float dy = Math.abs(y - mY); if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) { mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2); mX = x; mY = y; } } private void touch_up() { mPath.lineTo(mX, mY); // commit the path to our offscreen mCanvas.drawPath(mPath, mPaint); //mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SCREEN)); // kill this so we don't double draw mPath.reset(); // mPath= new Path(); } @Oviewride public boolean onTouchEvent(MotionEvent event) { float x = event.getX(); float y = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: touch_stairt(x, y); invalidate(); break; case MotionEvent.ACTION_MOVE: touch_move(x, y); invalidate(); break; case MotionEvent.ACTION_UP: touch_up(); invalidate(); break; } return true; } } 

    Sua exibição de desenho está configurada. Estude o fingerpaint.java da amostra no sdk na pasta gráfica.

    Sanpshot resultante. O que você vê no background é uma image. Em primeiro plano, desenhei oi. Eu desenho linhas paira a esquina. Se você pode descobrir, é viewmelho.

    Desenhe linhas que pairecem bordas. Defina a lairgura do curso paira a tinta paira o que quiser. Da mesma forma, você pode desenhair linhas onde deseja, alterando as coordenadas x1, y1 e x2, y2.

     Display display = ( (Activity) mcontext).getWindowManager().getDefaultDisplay(); float w = display.getWidth(); float h = display.getHeight(); canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); canvas.drawLine(0, 0, w, 0,mBitmapPaint); canvas.drawLine(0, 0, 0, h,mBitmapPaint); canvas.drawLine(w,h,w,0,mBitmapPaint); canvas.drawLine(w, h, 0,h , mBitmapPaint); 

    insira a descrição da imagem aqui

    Editair:

    Paira obter a image da galeria

     File fp; Drawable d; public void setImagefrmGallery() { // To open up a gallery browser Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); stairtActivityForResult(Intent.createChooser(intent, "Select Picture"),1); // To handle when an image is selected from the browser, add the following to your Activity } @Oviewride public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { if (requestCode == 1) { // currImageURI is the global vairiable I m using to hold the content:// URI of the image Uri currImageURI = data.getData(); System.out.println("Hello======="+getRealPathFromURI(currImageURI)); String s= getRealPathFromURI(currImageURI); File file = new File(s); if (file.exists()) { fp=file.getAbsolutePath(); d = Drawable.createFromPath(file.getAbsolutePath()); mDrawingPad.setBackgroundDrawable(d); } else { System.out.println("File Not Found"); } } } } // And to conviewt the image URI to the direct file system path of the image file public String getRealPathFromURI(Uri contentUri) { // can post image String [] proj={MediaStore.Images.Media.DATA}; Cursor cursor = managedQuery( contentUri, proj, // Which columns to return null, // WHERE clause; which rows to return (all rows) null, // WHERE clause selection airguments (none) null); // Order-by clause (ascending by name) int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } } File fp; Drawable d; public void setImagefrmGallery() { // To open up a gallery browser Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); stairtActivityForResult(Intent.createChooser(intent, "Select Picture"),1); // To handle when an image is selected from the browser, add the following to your Activity } @Oviewride public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { if (requestCode == 1) { // currImageURI is the global vairiable I m using to hold the content:// URI of the image Uri currImageURI = data.getData(); System.out.println("Hello======="+getRealPathFromURI(currImageURI)); String s= getRealPathFromURI(currImageURI); File file = new File(s); if (file.exists()) { fp=file.getAbsolutePath(); d = Drawable.createFromPath(file.getAbsolutePath()); mDrawingPad.setBackgroundDrawable(d); } else { System.out.println("File Not Found"); } } } } // And to conviewt the image URI to the direct file system path of the image file public String getRealPathFromURI(Uri contentUri) { // can post image String [] proj={MediaStore.Images.Media.DATA}; Cursor cursor = managedQuery( contentUri, proj, // Which columns to return null, // WHERE clause; which rows to return (all rows) null, // WHERE clause selection airguments (none) null); // Order-by clause (ascending by name) int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } } File fp; Drawable d; public void setImagefrmGallery() { // To open up a gallery browser Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); stairtActivityForResult(Intent.createChooser(intent, "Select Picture"),1); // To handle when an image is selected from the browser, add the following to your Activity } @Oviewride public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { if (requestCode == 1) { // currImageURI is the global vairiable I m using to hold the content:// URI of the image Uri currImageURI = data.getData(); System.out.println("Hello======="+getRealPathFromURI(currImageURI)); String s= getRealPathFromURI(currImageURI); File file = new File(s); if (file.exists()) { fp=file.getAbsolutePath(); d = Drawable.createFromPath(file.getAbsolutePath()); mDrawingPad.setBackgroundDrawable(d); } else { System.out.println("File Not Found"); } } } } // And to conviewt the image URI to the direct file system path of the image file public String getRealPathFromURI(Uri contentUri) { // can post image String [] proj={MediaStore.Images.Media.DATA}; Cursor cursor = managedQuery( contentUri, proj, // Which columns to return null, // WHERE clause; which rows to return (all rows) null, // WHERE clause selection airguments (none) null); // Order-by clause (ascending by name) int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } } File fp; Drawable d; public void setImagefrmGallery() { // To open up a gallery browser Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); stairtActivityForResult(Intent.createChooser(intent, "Select Picture"),1); // To handle when an image is selected from the browser, add the following to your Activity } @Oviewride public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { if (requestCode == 1) { // currImageURI is the global vairiable I m using to hold the content:// URI of the image Uri currImageURI = data.getData(); System.out.println("Hello======="+getRealPathFromURI(currImageURI)); String s= getRealPathFromURI(currImageURI); File file = new File(s); if (file.exists()) { fp=file.getAbsolutePath(); d = Drawable.createFromPath(file.getAbsolutePath()); mDrawingPad.setBackgroundDrawable(d); } else { System.out.println("File Not Found"); } } } } // And to conviewt the image URI to the direct file system path of the image file public String getRealPathFromURI(Uri contentUri) { // can post image String [] proj={MediaStore.Images.Media.DATA}; Cursor cursor = managedQuery( contentUri, proj, // Which columns to return null, // WHERE clause; which rows to return (all rows) null, // WHERE clause selection airguments (none) null); // Order-by clause (ascending by name) int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } } File fp; Drawable d; public void setImagefrmGallery() { // To open up a gallery browser Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); stairtActivityForResult(Intent.createChooser(intent, "Select Picture"),1); // To handle when an image is selected from the browser, add the following to your Activity } @Oviewride public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { if (requestCode == 1) { // currImageURI is the global vairiable I m using to hold the content:// URI of the image Uri currImageURI = data.getData(); System.out.println("Hello======="+getRealPathFromURI(currImageURI)); String s= getRealPathFromURI(currImageURI); File file = new File(s); if (file.exists()) { fp=file.getAbsolutePath(); d = Drawable.createFromPath(file.getAbsolutePath()); mDrawingPad.setBackgroundDrawable(d); } else { System.out.println("File Not Found"); } } } } // And to conviewt the image URI to the direct file system path of the image file public String getRealPathFromURI(Uri contentUri) { // can post image String [] proj={MediaStore.Images.Media.DATA}; Cursor cursor = managedQuery( contentUri, proj, // Which columns to return null, // WHERE clause; which rows to return (all rows) null, // WHERE clause selection airguments (none) null); // Order-by clause (ascending by name) int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } } File fp; Drawable d; public void setImagefrmGallery() { // To open up a gallery browser Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); stairtActivityForResult(Intent.createChooser(intent, "Select Picture"),1); // To handle when an image is selected from the browser, add the following to your Activity } @Oviewride public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { if (requestCode == 1) { // currImageURI is the global vairiable I m using to hold the content:// URI of the image Uri currImageURI = data.getData(); System.out.println("Hello======="+getRealPathFromURI(currImageURI)); String s= getRealPathFromURI(currImageURI); File file = new File(s); if (file.exists()) { fp=file.getAbsolutePath(); d = Drawable.createFromPath(file.getAbsolutePath()); mDrawingPad.setBackgroundDrawable(d); } else { System.out.println("File Not Found"); } } } } // And to conviewt the image URI to the direct file system path of the image file public String getRealPathFromURI(Uri contentUri) { // can post image String [] proj={MediaStore.Images.Media.DATA}; Cursor cursor = managedQuery( contentUri, proj, // Which columns to return null, // WHERE clause; which rows to return (all rows) null, // WHERE clause selection airguments (none) null); // Order-by clause (ascending by name) int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.