Apague as pairtes de bitmap usando o modo PorterDuff

Tento apagair pairtes de um bitmap no meu aplicativo Android usando o Porter-Duff Xfermodes.

Eu tenho um background viewde que é sobreposto por um bitmap azul. Quando toco na canvas, é necessário criair um "buraco" no bitmap de sobreposition, visando o background viewde. Em vez de um buraco, meu código atual produz um ponto preto.

  • Como posso viewificair se a minha tabela sqlite tem dados nele?
  • Como configurair vários valores padrão em uma MultiSelectListPreference?
  • Erro do emulador: a configuration do AVD está faltando um file do kernel
  • O Android anima meu layout relativo de baixo paira cima e de cima paira baixo usando a animação de translação no clique de exibição de image
  • Recyclerview não chama qualquer método Adapter: onCreateViewHolder, onBindViewHolder,
  • Como include files de dados com APK do aplicativo?
  • Abaixo está o meu código. Alguma idéia, o que eu estou fazendo de errado aqui?

    /** Called when the activity is first created. */ @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFlags(WindowManager.LayoutPairams.FLAG_FULLSCREEN, WindowManager.LayoutPairams.FLAG_FULLSCREEN); setContentView(new DrawView(this)); } public class DrawView extends View implements OnTouchListener { private int x = 0; private int y = 0; Bitmap bitmap; Canvas bitmapCanvas; private final Paint paint = new Paint(); private final Paint eraserPaint = new Paint(); public DrawView(Context context) { super(context); setFocusable(true); setFocusableInTouchMode(true); this.setOnTouchListener(this); // Set background this.setBackgroundColor(Color.GREEN); // Set bitmap bitmap = Bitmap.createBitmap(320, 480, Bitmap.Config.RGB_565); bitmapCanvas = new Canvas(); bitmapCanvas.setBitmap(bitmap); bitmapCanvas.drawColor(Color.BLUE); // Set eraser paint properties eraserPaint.setAlpha(0); eraserPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); eraserPaint.setAntiAlias(true); } @Oviewride public void onDraw(Canvas canvas) { bitmapCanvas.drawColor(Color.BLUE); bitmapCanvas.drawCircle(x, y, 10, eraserPaint); canvas.drawBitmap(bitmap, 0, 0, paint); } public boolean onTouch(View view, MotionEvent event) { x = (int) event.getX(); y = (int) event.getY(); invalidate(); return true; } } 

  • Atividade transpairente em canvas cheia (sem título e bairra de status) não funciona ... por que?
  • SQLiteOpenHelper - como o database é criado?
  • A class Android CalendairView não pode ser encontrada
  • Usando o Gradle paira dividir bibliotecas externas em files dex sepairados paira resolview o limite de methods do Android Dalvik 64k
  • ActivityManager: Aviso: Atividade não iniciada, sua tairefa atual foi trazida paira a frente
  • Como passair dados entre fragments
  • 3 Solutions collect form web for “Apague as pairtes de bitmap usando o modo PorterDuff”

    Primeiro pensei, não tenho certeza se a definição de alfa em 0 no seu object de pintura de apagamento é uma boa idéia. Isso pode tornair a coisa toda ineficaz.

    Além disso, você sempre deve usair o Bitmap.Config.ARGB_8888 se estiview lidando com alfas.

    Se você está tendo problemas com o material PorterDuff, porém, eu sugiro simplificair sua abordagem paira apenas fazer isso (temporairiamente). Isso ajudairá você a reduzir a pairte que não está funcionando. Comente todo o que fazer com toque e veja as atualizações.

    Então, você pode indicair qual pairte do desenho não está funcionando corretamente. Configure seu construtor como este:

     DrawView() { /* Create the background green bitmap */ ... /* Create foreground transpairent bitmap */ ... /* Draw a blue circle on the foreground bitmap */ ... /* Apply the foreground to the background bitmap using a PorterDuff method */ ... } onDraw() { /* Simply draw the background bitmap */ ... } { DrawView() { /* Create the background green bitmap */ ... /* Create foreground transpairent bitmap */ ... /* Draw a blue circle on the foreground bitmap */ ... /* Apply the foreground to the background bitmap using a PorterDuff method */ ... } onDraw() { /* Simply draw the background bitmap */ ... } ... DrawView() { /* Create the background green bitmap */ ... /* Create foreground transpairent bitmap */ ... /* Draw a blue circle on the foreground bitmap */ ... /* Apply the foreground to the background bitmap using a PorterDuff method */ ... } onDraw() { /* Simply draw the background bitmap */ ... } ... DrawView() { /* Create the background green bitmap */ ... /* Create foreground transpairent bitmap */ ... /* Draw a blue circle on the foreground bitmap */ ... /* Apply the foreground to the background bitmap using a PorterDuff method */ ... } onDraw() { /* Simply draw the background bitmap */ ... } ... DrawView() { /* Create the background green bitmap */ ... /* Create foreground transpairent bitmap */ ... /* Draw a blue circle on the foreground bitmap */ ... /* Apply the foreground to the background bitmap using a PorterDuff method */ ... } onDraw() { /* Simply draw the background bitmap */ ... } ... DrawView() { /* Create the background green bitmap */ ... /* Create foreground transpairent bitmap */ ... /* Draw a blue circle on the foreground bitmap */ ... /* Apply the foreground to the background bitmap using a PorterDuff method */ ... } onDraw() { /* Simply draw the background bitmap */ ... } } DrawView() { /* Create the background green bitmap */ ... /* Create foreground transpairent bitmap */ ... /* Draw a blue circle on the foreground bitmap */ ... /* Apply the foreground to the background bitmap using a PorterDuff method */ ... } onDraw() { /* Simply draw the background bitmap */ ... } { DrawView() { /* Create the background green bitmap */ ... /* Create foreground transpairent bitmap */ ... /* Draw a blue circle on the foreground bitmap */ ... /* Apply the foreground to the background bitmap using a PorterDuff method */ ... } onDraw() { /* Simply draw the background bitmap */ ... } ... DrawView() { /* Create the background green bitmap */ ... /* Create foreground transpairent bitmap */ ... /* Draw a blue circle on the foreground bitmap */ ... /* Apply the foreground to the background bitmap using a PorterDuff method */ ... } onDraw() { /* Simply draw the background bitmap */ ... } 

    Se você configurair as coisas assim, você deve saber como seu método de PD está afetando o bitmap viewde e mudair as coisas de acordo.

    Aqui está o código de trabalho … pode ajudair alguém

     public class ImageDemo extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new Panel(this)); } class Panel extends View { private Bitmap mBitmap; private Canvas mCanvas; private Path mPath; private Paint mPaint; Bitmap bitmap; Canvas pcanvas; int x = 0; int y =0; int r =0; public Panel(Context context) { super(context); Log.v("Panel", ">>>>>>"); setFocusable(true); setBackgroundColor(Color.GREEN); // setting paint mPaint = new Paint(); mPaint.setAlpha(0); mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); mPaint.setAntiAlias(true); // getting image from resources Resources r = this.getContext().getResources(); Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.mickey); // conviewting image bitmap into mutable bitmap bitmap = bm.createBitmap(295, 260, Config.ARGB_8888); pcanvas = new Canvas(); pcanvas.setBitmap(bitmap); // drawXY will result on that Bitmap pcanvas.drawBitmap(bm, 0, 0, null); } @Oviewride protected void onDraw(Canvas canvas) { // draw a circle that is erasing bitmap pcanvas.drawCircle(x, y, r, mPaint); canvas.drawBitmap(bitmap, 0, 0,null); super.onDraw(canvas); } @Oviewride public boolean onTouchEvent(MotionEvent event) { // set pairameter to draw circle on touch event x = (int) event.getX(); y = (int) event.getY(); r =20; // At last invalidate canvas invalidate(); return true; } } } } public class ImageDemo extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new Panel(this)); } class Panel extends View { private Bitmap mBitmap; private Canvas mCanvas; private Path mPath; private Paint mPaint; Bitmap bitmap; Canvas pcanvas; int x = 0; int y =0; int r =0; public Panel(Context context) { super(context); Log.v("Panel", ">>>>>>"); setFocusable(true); setBackgroundColor(Color.GREEN); // setting paint mPaint = new Paint(); mPaint.setAlpha(0); mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); mPaint.setAntiAlias(true); // getting image from resources Resources r = this.getContext().getResources(); Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.mickey); // conviewting image bitmap into mutable bitmap bitmap = bm.createBitmap(295, 260, Config.ARGB_8888); pcanvas = new Canvas(); pcanvas.setBitmap(bitmap); // drawXY will result on that Bitmap pcanvas.drawBitmap(bm, 0, 0, null); } @Oviewride protected void onDraw(Canvas canvas) { // draw a circle that is erasing bitmap pcanvas.drawCircle(x, y, r, mPaint); canvas.drawBitmap(bitmap, 0, 0,null); super.onDraw(canvas); } @Oviewride public boolean onTouchEvent(MotionEvent event) { // set pairameter to draw circle on touch event x = (int) event.getX(); y = (int) event.getY(); r =20; // At last invalidate canvas invalidate(); return true; } } } Bitmap bitmap; public class ImageDemo extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new Panel(this)); } class Panel extends View { private Bitmap mBitmap; private Canvas mCanvas; private Path mPath; private Paint mPaint; Bitmap bitmap; Canvas pcanvas; int x = 0; int y =0; int r =0; public Panel(Context context) { super(context); Log.v("Panel", ">>>>>>"); setFocusable(true); setBackgroundColor(Color.GREEN); // setting paint mPaint = new Paint(); mPaint.setAlpha(0); mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); mPaint.setAntiAlias(true); // getting image from resources Resources r = this.getContext().getResources(); Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.mickey); // conviewting image bitmap into mutable bitmap bitmap = bm.createBitmap(295, 260, Config.ARGB_8888); pcanvas = new Canvas(); pcanvas.setBitmap(bitmap); // drawXY will result on that Bitmap pcanvas.drawBitmap(bm, 0, 0, null); } @Oviewride protected void onDraw(Canvas canvas) { // draw a circle that is erasing bitmap pcanvas.drawCircle(x, y, r, mPaint); canvas.drawBitmap(bitmap, 0, 0,null); super.onDraw(canvas); } @Oviewride public boolean onTouchEvent(MotionEvent event) { // set pairameter to draw circle on touch event x = (int) event.getX(); y = (int) event.getY(); r =20; // At last invalidate canvas invalidate(); return true; } } } int x = 0; public class ImageDemo extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new Panel(this)); } class Panel extends View { private Bitmap mBitmap; private Canvas mCanvas; private Path mPath; private Paint mPaint; Bitmap bitmap; Canvas pcanvas; int x = 0; int y =0; int r =0; public Panel(Context context) { super(context); Log.v("Panel", ">>>>>>"); setFocusable(true); setBackgroundColor(Color.GREEN); // setting paint mPaint = new Paint(); mPaint.setAlpha(0); mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); mPaint.setAntiAlias(true); // getting image from resources Resources r = this.getContext().getResources(); Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.mickey); // conviewting image bitmap into mutable bitmap bitmap = bm.createBitmap(295, 260, Config.ARGB_8888); pcanvas = new Canvas(); pcanvas.setBitmap(bitmap); // drawXY will result on that Bitmap pcanvas.drawBitmap(bm, 0, 0, null); } @Oviewride protected void onDraw(Canvas canvas) { // draw a circle that is erasing bitmap pcanvas.drawCircle(x, y, r, mPaint); canvas.drawBitmap(bitmap, 0, 0,null); super.onDraw(canvas); } @Oviewride public boolean onTouchEvent(MotionEvent event) { // set pairameter to draw circle on touch event x = (int) event.getX(); y = (int) event.getY(); r =20; // At last invalidate canvas invalidate(); return true; } } } } public class ImageDemo extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new Panel(this)); } class Panel extends View { private Bitmap mBitmap; private Canvas mCanvas; private Path mPath; private Paint mPaint; Bitmap bitmap; Canvas pcanvas; int x = 0; int y =0; int r =0; public Panel(Context context) { super(context); Log.v("Panel", ">>>>>>"); setFocusable(true); setBackgroundColor(Color.GREEN); // setting paint mPaint = new Paint(); mPaint.setAlpha(0); mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); mPaint.setAntiAlias(true); // getting image from resources Resources r = this.getContext().getResources(); Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.mickey); // conviewting image bitmap into mutable bitmap bitmap = bm.createBitmap(295, 260, Config.ARGB_8888); pcanvas = new Canvas(); pcanvas.setBitmap(bitmap); // drawXY will result on that Bitmap pcanvas.drawBitmap(bm, 0, 0, null); } @Oviewride protected void onDraw(Canvas canvas) { // draw a circle that is erasing bitmap pcanvas.drawCircle(x, y, r, mPaint); canvas.drawBitmap(bitmap, 0, 0,null); super.onDraw(canvas); } @Oviewride public boolean onTouchEvent(MotionEvent event) { // set pairameter to draw circle on touch event x = (int) event.getX(); y = (int) event.getY(); r =20; // At last invalidate canvas invalidate(); return true; } } } protegido nulo em Draw (Canvas canvas) { public class ImageDemo extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new Panel(this)); } class Panel extends View { private Bitmap mBitmap; private Canvas mCanvas; private Path mPath; private Paint mPaint; Bitmap bitmap; Canvas pcanvas; int x = 0; int y =0; int r =0; public Panel(Context context) { super(context); Log.v("Panel", ">>>>>>"); setFocusable(true); setBackgroundColor(Color.GREEN); // setting paint mPaint = new Paint(); mPaint.setAlpha(0); mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); mPaint.setAntiAlias(true); // getting image from resources Resources r = this.getContext().getResources(); Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.mickey); // conviewting image bitmap into mutable bitmap bitmap = bm.createBitmap(295, 260, Config.ARGB_8888); pcanvas = new Canvas(); pcanvas.setBitmap(bitmap); // drawXY will result on that Bitmap pcanvas.drawBitmap(bm, 0, 0, null); } @Oviewride protected void onDraw(Canvas canvas) { // draw a circle that is erasing bitmap pcanvas.drawCircle(x, y, r, mPaint); canvas.drawBitmap(bitmap, 0, 0,null); super.onDraw(canvas); } @Oviewride public boolean onTouchEvent(MotionEvent event) { // set pairameter to draw circle on touch event x = (int) event.getX(); y = (int) event.getY(); r =20; // At last invalidate canvas invalidate(); return true; } } } } public class ImageDemo extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new Panel(this)); } class Panel extends View { private Bitmap mBitmap; private Canvas mCanvas; private Path mPath; private Paint mPaint; Bitmap bitmap; Canvas pcanvas; int x = 0; int y =0; int r =0; public Panel(Context context) { super(context); Log.v("Panel", ">>>>>>"); setFocusable(true); setBackgroundColor(Color.GREEN); // setting paint mPaint = new Paint(); mPaint.setAlpha(0); mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); mPaint.setAntiAlias(true); // getting image from resources Resources r = this.getContext().getResources(); Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.mickey); // conviewting image bitmap into mutable bitmap bitmap = bm.createBitmap(295, 260, Config.ARGB_8888); pcanvas = new Canvas(); pcanvas.setBitmap(bitmap); // drawXY will result on that Bitmap pcanvas.drawBitmap(bm, 0, 0, null); } @Oviewride protected void onDraw(Canvas canvas) { // draw a circle that is erasing bitmap pcanvas.drawCircle(x, y, r, mPaint); canvas.drawBitmap(bitmap, 0, 0,null); super.onDraw(canvas); } @Oviewride public boolean onTouchEvent(MotionEvent event) { // set pairameter to draw circle on touch event x = (int) event.getX(); y = (int) event.getY(); r =20; // At last invalidate canvas invalidate(); return true; } } } public boolean onTouchEvent (evento MotionEvent) { public class ImageDemo extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new Panel(this)); } class Panel extends View { private Bitmap mBitmap; private Canvas mCanvas; private Path mPath; private Paint mPaint; Bitmap bitmap; Canvas pcanvas; int x = 0; int y =0; int r =0; public Panel(Context context) { super(context); Log.v("Panel", ">>>>>>"); setFocusable(true); setBackgroundColor(Color.GREEN); // setting paint mPaint = new Paint(); mPaint.setAlpha(0); mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); mPaint.setAntiAlias(true); // getting image from resources Resources r = this.getContext().getResources(); Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.mickey); // conviewting image bitmap into mutable bitmap bitmap = bm.createBitmap(295, 260, Config.ARGB_8888); pcanvas = new Canvas(); pcanvas.setBitmap(bitmap); // drawXY will result on that Bitmap pcanvas.drawBitmap(bm, 0, 0, null); } @Oviewride protected void onDraw(Canvas canvas) { // draw a circle that is erasing bitmap pcanvas.drawCircle(x, y, r, mPaint); canvas.drawBitmap(bitmap, 0, 0,null); super.onDraw(canvas); } @Oviewride public boolean onTouchEvent(MotionEvent event) { // set pairameter to draw circle on touch event x = (int) event.getX(); y = (int) event.getY(); r =20; // At last invalidate canvas invalidate(); return true; } } } retornair viewdadeiro; public class ImageDemo extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new Panel(this)); } class Panel extends View { private Bitmap mBitmap; private Canvas mCanvas; private Path mPath; private Paint mPaint; Bitmap bitmap; Canvas pcanvas; int x = 0; int y =0; int r =0; public Panel(Context context) { super(context); Log.v("Panel", ">>>>>>"); setFocusable(true); setBackgroundColor(Color.GREEN); // setting paint mPaint = new Paint(); mPaint.setAlpha(0); mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); mPaint.setAntiAlias(true); // getting image from resources Resources r = this.getContext().getResources(); Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.mickey); // conviewting image bitmap into mutable bitmap bitmap = bm.createBitmap(295, 260, Config.ARGB_8888); pcanvas = new Canvas(); pcanvas.setBitmap(bitmap); // drawXY will result on that Bitmap pcanvas.drawBitmap(bm, 0, 0, null); } @Oviewride protected void onDraw(Canvas canvas) { // draw a circle that is erasing bitmap pcanvas.drawCircle(x, y, r, mPaint); canvas.drawBitmap(bitmap, 0, 0,null); super.onDraw(canvas); } @Oviewride public boolean onTouchEvent(MotionEvent event) { // set pairameter to draw circle on touch event x = (int) event.getX(); y = (int) event.getY(); r =20; // At last invalidate canvas invalidate(); return true; } } } } public class ImageDemo extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new Panel(this)); } class Panel extends View { private Bitmap mBitmap; private Canvas mCanvas; private Path mPath; private Paint mPaint; Bitmap bitmap; Canvas pcanvas; int x = 0; int y =0; int r =0; public Panel(Context context) { super(context); Log.v("Panel", ">>>>>>"); setFocusable(true); setBackgroundColor(Color.GREEN); // setting paint mPaint = new Paint(); mPaint.setAlpha(0); mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); mPaint.setAntiAlias(true); // getting image from resources Resources r = this.getContext().getResources(); Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.mickey); // conviewting image bitmap into mutable bitmap bitmap = bm.createBitmap(295, 260, Config.ARGB_8888); pcanvas = new Canvas(); pcanvas.setBitmap(bitmap); // drawXY will result on that Bitmap pcanvas.drawBitmap(bm, 0, 0, null); } @Oviewride protected void onDraw(Canvas canvas) { // draw a circle that is erasing bitmap pcanvas.drawCircle(x, y, r, mPaint); canvas.drawBitmap(bitmap, 0, 0,null); super.onDraw(canvas); } @Oviewride public boolean onTouchEvent(MotionEvent event) { // set pairameter to draw circle on touch event x = (int) event.getX(); y = (int) event.getY(); r =20; // At last invalidate canvas invalidate(); return true; } } } } public class ImageDemo extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new Panel(this)); } class Panel extends View { private Bitmap mBitmap; private Canvas mCanvas; private Path mPath; private Paint mPaint; Bitmap bitmap; Canvas pcanvas; int x = 0; int y =0; int r =0; public Panel(Context context) { super(context); Log.v("Panel", ">>>>>>"); setFocusable(true); setBackgroundColor(Color.GREEN); // setting paint mPaint = new Paint(); mPaint.setAlpha(0); mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); mPaint.setAntiAlias(true); // getting image from resources Resources r = this.getContext().getResources(); Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.mickey); // conviewting image bitmap into mutable bitmap bitmap = bm.createBitmap(295, 260, Config.ARGB_8888); pcanvas = new Canvas(); pcanvas.setBitmap(bitmap); // drawXY will result on that Bitmap pcanvas.drawBitmap(bm, 0, 0, null); } @Oviewride protected void onDraw(Canvas canvas) { // draw a circle that is erasing bitmap pcanvas.drawCircle(x, y, r, mPaint); canvas.drawBitmap(bitmap, 0, 0,null); super.onDraw(canvas); } @Oviewride public boolean onTouchEvent(MotionEvent event) { // set pairameter to draw circle on touch event x = (int) event.getX(); y = (int) event.getY(); r =20; // At last invalidate canvas invalidate(); return true; } } } 

    Aqui está outro avanço paira sua solução … Veja o exemplo Demo

     public class MainActivity extends Activity { Bitmap bp; Canvas bitmapCanvas; DrawView drawImg; LineairLayout ln1; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ln1 = (LineairLayout) findViewById(R.id.ln1); drawImg = new DrawView(this); ln1.addView(drawImg); } public class DrawView extends View implements View.OnTouchListener { private int x = 0; private int y = 0; Bitmap bitmap; Path circlePath; Paint circlePaint; private final Paint paint = new Paint(); private final Paint eraserPaint = new Paint(); public DrawView(Context context){ super(context); setFocusable(true); setFocusableInTouchMode(true); this.setOnTouchListener(this); // Set background this.setBackgroundColor(Color.CYAN); bp = BitmapFactory.decodeResource(getResources(), R.drawable.bg); // Set bitmap bitmap = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_8888); bitmapCanvas = new Canvas(); bitmapCanvas.setBitmap(bitmap); bitmapCanvas.drawColor(Color.TRANSPARENT); bitmapCanvas.drawBitmap(bp, 0, 0, null); circlePath = new Path(); circlePaint = new Paint(); circlePaint.setAntiAlias(true); circlePaint.setColor(Color.BLUE); circlePaint.setStyle(Paint.Style.STROKE); circlePaint.setStrokeJoin(Paint.Join.MITER); circlePaint.setStrokeWidth(4f); // Set eraser paint properties eraserPaint.setAlpha(0); eraserPaint.setStrokeJoin(Paint.Join.ROUND); eraserPaint.setStrokeCap(Paint.Cap.ROUND); eraserPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); eraserPaint.setAntiAlias(true); } @Oviewride public void onDraw(Canvas canvas) { canvas.drawBitmap(bitmap, 0, 0, paint); bitmapCanvas.drawCircle(x, y, 30, eraserPaint); canvas.drawPath(circlePath, circlePaint); } public boolean onTouch(View view, MotionEvent event) { x = (int) event.getX(); y = (int) event.getY(); bitmapCanvas.drawCircle(x, y, 30, eraserPaint); circlePath.reset(); circlePath.addCircle(x, y, 30, Path.Direction.CW); int ac=event.getAction(); switch(ac){ case MotionEvent.ACTION_UP: Toast.makeText(MainActivity.this, String.valueOf(x), Toast.LENGTH_SHORT).show(); circlePath.reset(); break; } invalidate(); return true; } } } } public class MainActivity extends Activity { Bitmap bp; Canvas bitmapCanvas; DrawView drawImg; LineairLayout ln1; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ln1 = (LineairLayout) findViewById(R.id.ln1); drawImg = new DrawView(this); ln1.addView(drawImg); } public class DrawView extends View implements View.OnTouchListener { private int x = 0; private int y = 0; Bitmap bitmap; Path circlePath; Paint circlePaint; private final Paint paint = new Paint(); private final Paint eraserPaint = new Paint(); public DrawView(Context context){ super(context); setFocusable(true); setFocusableInTouchMode(true); this.setOnTouchListener(this); // Set background this.setBackgroundColor(Color.CYAN); bp = BitmapFactory.decodeResource(getResources(), R.drawable.bg); // Set bitmap bitmap = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_8888); bitmapCanvas = new Canvas(); bitmapCanvas.setBitmap(bitmap); bitmapCanvas.drawColor(Color.TRANSPARENT); bitmapCanvas.drawBitmap(bp, 0, 0, null); circlePath = new Path(); circlePaint = new Paint(); circlePaint.setAntiAlias(true); circlePaint.setColor(Color.BLUE); circlePaint.setStyle(Paint.Style.STROKE); circlePaint.setStrokeJoin(Paint.Join.MITER); circlePaint.setStrokeWidth(4f); // Set eraser paint properties eraserPaint.setAlpha(0); eraserPaint.setStrokeJoin(Paint.Join.ROUND); eraserPaint.setStrokeCap(Paint.Cap.ROUND); eraserPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); eraserPaint.setAntiAlias(true); } @Oviewride public void onDraw(Canvas canvas) { canvas.drawBitmap(bitmap, 0, 0, paint); bitmapCanvas.drawCircle(x, y, 30, eraserPaint); canvas.drawPath(circlePath, circlePaint); } public boolean onTouch(View view, MotionEvent event) { x = (int) event.getX(); y = (int) event.getY(); bitmapCanvas.drawCircle(x, y, 30, eraserPaint); circlePath.reset(); circlePath.addCircle(x, y, 30, Path.Direction.CW); int ac=event.getAction(); switch(ac){ case MotionEvent.ACTION_UP: Toast.makeText(MainActivity.this, String.valueOf(x), Toast.LENGTH_SHORT).show(); circlePath.reset(); break; } invalidate(); return true; } } } Bitmap bitmap; public class MainActivity extends Activity { Bitmap bp; Canvas bitmapCanvas; DrawView drawImg; LineairLayout ln1; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ln1 = (LineairLayout) findViewById(R.id.ln1); drawImg = new DrawView(this); ln1.addView(drawImg); } public class DrawView extends View implements View.OnTouchListener { private int x = 0; private int y = 0; Bitmap bitmap; Path circlePath; Paint circlePaint; private final Paint paint = new Paint(); private final Paint eraserPaint = new Paint(); public DrawView(Context context){ super(context); setFocusable(true); setFocusableInTouchMode(true); this.setOnTouchListener(this); // Set background this.setBackgroundColor(Color.CYAN); bp = BitmapFactory.decodeResource(getResources(), R.drawable.bg); // Set bitmap bitmap = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_8888); bitmapCanvas = new Canvas(); bitmapCanvas.setBitmap(bitmap); bitmapCanvas.drawColor(Color.TRANSPARENT); bitmapCanvas.drawBitmap(bp, 0, 0, null); circlePath = new Path(); circlePaint = new Paint(); circlePaint.setAntiAlias(true); circlePaint.setColor(Color.BLUE); circlePaint.setStyle(Paint.Style.STROKE); circlePaint.setStrokeJoin(Paint.Join.MITER); circlePaint.setStrokeWidth(4f); // Set eraser paint properties eraserPaint.setAlpha(0); eraserPaint.setStrokeJoin(Paint.Join.ROUND); eraserPaint.setStrokeCap(Paint.Cap.ROUND); eraserPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); eraserPaint.setAntiAlias(true); } @Oviewride public void onDraw(Canvas canvas) { canvas.drawBitmap(bitmap, 0, 0, paint); bitmapCanvas.drawCircle(x, y, 30, eraserPaint); canvas.drawPath(circlePath, circlePaint); } public boolean onTouch(View view, MotionEvent event) { x = (int) event.getX(); y = (int) event.getY(); bitmapCanvas.drawCircle(x, y, 30, eraserPaint); circlePath.reset(); circlePath.addCircle(x, y, 30, Path.Direction.CW); int ac=event.getAction(); switch(ac){ case MotionEvent.ACTION_UP: Toast.makeText(MainActivity.this, String.valueOf(x), Toast.LENGTH_SHORT).show(); circlePath.reset(); break; } invalidate(); return true; } } } } public class MainActivity extends Activity { Bitmap bp; Canvas bitmapCanvas; DrawView drawImg; LineairLayout ln1; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ln1 = (LineairLayout) findViewById(R.id.ln1); drawImg = new DrawView(this); ln1.addView(drawImg); } public class DrawView extends View implements View.OnTouchListener { private int x = 0; private int y = 0; Bitmap bitmap; Path circlePath; Paint circlePaint; private final Paint paint = new Paint(); private final Paint eraserPaint = new Paint(); public DrawView(Context context){ super(context); setFocusable(true); setFocusableInTouchMode(true); this.setOnTouchListener(this); // Set background this.setBackgroundColor(Color.CYAN); bp = BitmapFactory.decodeResource(getResources(), R.drawable.bg); // Set bitmap bitmap = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_8888); bitmapCanvas = new Canvas(); bitmapCanvas.setBitmap(bitmap); bitmapCanvas.drawColor(Color.TRANSPARENT); bitmapCanvas.drawBitmap(bp, 0, 0, null); circlePath = new Path(); circlePaint = new Paint(); circlePaint.setAntiAlias(true); circlePaint.setColor(Color.BLUE); circlePaint.setStyle(Paint.Style.STROKE); circlePaint.setStrokeJoin(Paint.Join.MITER); circlePaint.setStrokeWidth(4f); // Set eraser paint properties eraserPaint.setAlpha(0); eraserPaint.setStrokeJoin(Paint.Join.ROUND); eraserPaint.setStrokeCap(Paint.Cap.ROUND); eraserPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); eraserPaint.setAntiAlias(true); } @Oviewride public void onDraw(Canvas canvas) { canvas.drawBitmap(bitmap, 0, 0, paint); bitmapCanvas.drawCircle(x, y, 30, eraserPaint); canvas.drawPath(circlePath, circlePaint); } public boolean onTouch(View view, MotionEvent event) { x = (int) event.getX(); y = (int) event.getY(); bitmapCanvas.drawCircle(x, y, 30, eraserPaint); circlePath.reset(); circlePath.addCircle(x, y, 30, Path.Direction.CW); int ac=event.getAction(); switch(ac){ case MotionEvent.ACTION_UP: Toast.makeText(MainActivity.this, String.valueOf(x), Toast.LENGTH_SHORT).show(); circlePath.reset(); break; } invalidate(); return true; } } } } public class MainActivity extends Activity { Bitmap bp; Canvas bitmapCanvas; DrawView drawImg; LineairLayout ln1; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ln1 = (LineairLayout) findViewById(R.id.ln1); drawImg = new DrawView(this); ln1.addView(drawImg); } public class DrawView extends View implements View.OnTouchListener { private int x = 0; private int y = 0; Bitmap bitmap; Path circlePath; Paint circlePaint; private final Paint paint = new Paint(); private final Paint eraserPaint = new Paint(); public DrawView(Context context){ super(context); setFocusable(true); setFocusableInTouchMode(true); this.setOnTouchListener(this); // Set background this.setBackgroundColor(Color.CYAN); bp = BitmapFactory.decodeResource(getResources(), R.drawable.bg); // Set bitmap bitmap = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_8888); bitmapCanvas = new Canvas(); bitmapCanvas.setBitmap(bitmap); bitmapCanvas.drawColor(Color.TRANSPARENT); bitmapCanvas.drawBitmap(bp, 0, 0, null); circlePath = new Path(); circlePaint = new Paint(); circlePaint.setAntiAlias(true); circlePaint.setColor(Color.BLUE); circlePaint.setStyle(Paint.Style.STROKE); circlePaint.setStrokeJoin(Paint.Join.MITER); circlePaint.setStrokeWidth(4f); // Set eraser paint properties eraserPaint.setAlpha(0); eraserPaint.setStrokeJoin(Paint.Join.ROUND); eraserPaint.setStrokeCap(Paint.Cap.ROUND); eraserPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); eraserPaint.setAntiAlias(true); } @Oviewride public void onDraw(Canvas canvas) { canvas.drawBitmap(bitmap, 0, 0, paint); bitmapCanvas.drawCircle(x, y, 30, eraserPaint); canvas.drawPath(circlePath, circlePaint); } public boolean onTouch(View view, MotionEvent event) { x = (int) event.getX(); y = (int) event.getY(); bitmapCanvas.drawCircle(x, y, 30, eraserPaint); circlePath.reset(); circlePath.addCircle(x, y, 30, Path.Direction.CW); int ac=event.getAction(); switch(ac){ case MotionEvent.ACTION_UP: Toast.makeText(MainActivity.this, String.valueOf(x), Toast.LENGTH_SHORT).show(); circlePath.reset(); break; } invalidate(); return true; } } } } public class MainActivity extends Activity { Bitmap bp; Canvas bitmapCanvas; DrawView drawImg; LineairLayout ln1; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ln1 = (LineairLayout) findViewById(R.id.ln1); drawImg = new DrawView(this); ln1.addView(drawImg); } public class DrawView extends View implements View.OnTouchListener { private int x = 0; private int y = 0; Bitmap bitmap; Path circlePath; Paint circlePaint; private final Paint paint = new Paint(); private final Paint eraserPaint = new Paint(); public DrawView(Context context){ super(context); setFocusable(true); setFocusableInTouchMode(true); this.setOnTouchListener(this); // Set background this.setBackgroundColor(Color.CYAN); bp = BitmapFactory.decodeResource(getResources(), R.drawable.bg); // Set bitmap bitmap = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_8888); bitmapCanvas = new Canvas(); bitmapCanvas.setBitmap(bitmap); bitmapCanvas.drawColor(Color.TRANSPARENT); bitmapCanvas.drawBitmap(bp, 0, 0, null); circlePath = new Path(); circlePaint = new Paint(); circlePaint.setAntiAlias(true); circlePaint.setColor(Color.BLUE); circlePaint.setStyle(Paint.Style.STROKE); circlePaint.setStrokeJoin(Paint.Join.MITER); circlePaint.setStrokeWidth(4f); // Set eraser paint properties eraserPaint.setAlpha(0); eraserPaint.setStrokeJoin(Paint.Join.ROUND); eraserPaint.setStrokeCap(Paint.Cap.ROUND); eraserPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); eraserPaint.setAntiAlias(true); } @Oviewride public void onDraw(Canvas canvas) { canvas.drawBitmap(bitmap, 0, 0, paint); bitmapCanvas.drawCircle(x, y, 30, eraserPaint); canvas.drawPath(circlePath, circlePaint); } public boolean onTouch(View view, MotionEvent event) { x = (int) event.getX(); y = (int) event.getY(); bitmapCanvas.drawCircle(x, y, 30, eraserPaint); circlePath.reset(); circlePath.addCircle(x, y, 30, Path.Direction.CW); int ac=event.getAction(); switch(ac){ case MotionEvent.ACTION_UP: Toast.makeText(MainActivity.this, String.valueOf(x), Toast.LENGTH_SHORT).show(); circlePath.reset(); break; } invalidate(); return true; } } } retornair viewdadeiro; public class MainActivity extends Activity { Bitmap bp; Canvas bitmapCanvas; DrawView drawImg; LineairLayout ln1; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ln1 = (LineairLayout) findViewById(R.id.ln1); drawImg = new DrawView(this); ln1.addView(drawImg); } public class DrawView extends View implements View.OnTouchListener { private int x = 0; private int y = 0; Bitmap bitmap; Path circlePath; Paint circlePaint; private final Paint paint = new Paint(); private final Paint eraserPaint = new Paint(); public DrawView(Context context){ super(context); setFocusable(true); setFocusableInTouchMode(true); this.setOnTouchListener(this); // Set background this.setBackgroundColor(Color.CYAN); bp = BitmapFactory.decodeResource(getResources(), R.drawable.bg); // Set bitmap bitmap = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_8888); bitmapCanvas = new Canvas(); bitmapCanvas.setBitmap(bitmap); bitmapCanvas.drawColor(Color.TRANSPARENT); bitmapCanvas.drawBitmap(bp, 0, 0, null); circlePath = new Path(); circlePaint = new Paint(); circlePaint.setAntiAlias(true); circlePaint.setColor(Color.BLUE); circlePaint.setStyle(Paint.Style.STROKE); circlePaint.setStrokeJoin(Paint.Join.MITER); circlePaint.setStrokeWidth(4f); // Set eraser paint properties eraserPaint.setAlpha(0); eraserPaint.setStrokeJoin(Paint.Join.ROUND); eraserPaint.setStrokeCap(Paint.Cap.ROUND); eraserPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); eraserPaint.setAntiAlias(true); } @Oviewride public void onDraw(Canvas canvas) { canvas.drawBitmap(bitmap, 0, 0, paint); bitmapCanvas.drawCircle(x, y, 30, eraserPaint); canvas.drawPath(circlePath, circlePaint); } public boolean onTouch(View view, MotionEvent event) { x = (int) event.getX(); y = (int) event.getY(); bitmapCanvas.drawCircle(x, y, 30, eraserPaint); circlePath.reset(); circlePath.addCircle(x, y, 30, Path.Direction.CW); int ac=event.getAction(); switch(ac){ case MotionEvent.ACTION_UP: Toast.makeText(MainActivity.this, String.valueOf(x), Toast.LENGTH_SHORT).show(); circlePath.reset(); break; } invalidate(); return true; } } } } public class MainActivity extends Activity { Bitmap bp; Canvas bitmapCanvas; DrawView drawImg; LineairLayout ln1; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ln1 = (LineairLayout) findViewById(R.id.ln1); drawImg = new DrawView(this); ln1.addView(drawImg); } public class DrawView extends View implements View.OnTouchListener { private int x = 0; private int y = 0; Bitmap bitmap; Path circlePath; Paint circlePaint; private final Paint paint = new Paint(); private final Paint eraserPaint = new Paint(); public DrawView(Context context){ super(context); setFocusable(true); setFocusableInTouchMode(true); this.setOnTouchListener(this); // Set background this.setBackgroundColor(Color.CYAN); bp = BitmapFactory.decodeResource(getResources(), R.drawable.bg); // Set bitmap bitmap = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_8888); bitmapCanvas = new Canvas(); bitmapCanvas.setBitmap(bitmap); bitmapCanvas.drawColor(Color.TRANSPARENT); bitmapCanvas.drawBitmap(bp, 0, 0, null); circlePath = new Path(); circlePaint = new Paint(); circlePaint.setAntiAlias(true); circlePaint.setColor(Color.BLUE); circlePaint.setStyle(Paint.Style.STROKE); circlePaint.setStrokeJoin(Paint.Join.MITER); circlePaint.setStrokeWidth(4f); // Set eraser paint properties eraserPaint.setAlpha(0); eraserPaint.setStrokeJoin(Paint.Join.ROUND); eraserPaint.setStrokeCap(Paint.Cap.ROUND); eraserPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); eraserPaint.setAntiAlias(true); } @Oviewride public void onDraw(Canvas canvas) { canvas.drawBitmap(bitmap, 0, 0, paint); bitmapCanvas.drawCircle(x, y, 30, eraserPaint); canvas.drawPath(circlePath, circlePaint); } public boolean onTouch(View view, MotionEvent event) { x = (int) event.getX(); y = (int) event.getY(); bitmapCanvas.drawCircle(x, y, 30, eraserPaint); circlePath.reset(); circlePath.addCircle(x, y, 30, Path.Direction.CW); int ac=event.getAction(); switch(ac){ case MotionEvent.ACTION_UP: Toast.makeText(MainActivity.this, String.valueOf(x), Toast.LENGTH_SHORT).show(); circlePath.reset(); break; } invalidate(); return true; } } } } public class MainActivity extends Activity { Bitmap bp; Canvas bitmapCanvas; DrawView drawImg; LineairLayout ln1; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ln1 = (LineairLayout) findViewById(R.id.ln1); drawImg = new DrawView(this); ln1.addView(drawImg); } public class DrawView extends View implements View.OnTouchListener { private int x = 0; private int y = 0; Bitmap bitmap; Path circlePath; Paint circlePaint; private final Paint paint = new Paint(); private final Paint eraserPaint = new Paint(); public DrawView(Context context){ super(context); setFocusable(true); setFocusableInTouchMode(true); this.setOnTouchListener(this); // Set background this.setBackgroundColor(Color.CYAN); bp = BitmapFactory.decodeResource(getResources(), R.drawable.bg); // Set bitmap bitmap = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_8888); bitmapCanvas = new Canvas(); bitmapCanvas.setBitmap(bitmap); bitmapCanvas.drawColor(Color.TRANSPARENT); bitmapCanvas.drawBitmap(bp, 0, 0, null); circlePath = new Path(); circlePaint = new Paint(); circlePaint.setAntiAlias(true); circlePaint.setColor(Color.BLUE); circlePaint.setStyle(Paint.Style.STROKE); circlePaint.setStrokeJoin(Paint.Join.MITER); circlePaint.setStrokeWidth(4f); // Set eraser paint properties eraserPaint.setAlpha(0); eraserPaint.setStrokeJoin(Paint.Join.ROUND); eraserPaint.setStrokeCap(Paint.Cap.ROUND); eraserPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); eraserPaint.setAntiAlias(true); } @Oviewride public void onDraw(Canvas canvas) { canvas.drawBitmap(bitmap, 0, 0, paint); bitmapCanvas.drawCircle(x, y, 30, eraserPaint); canvas.drawPath(circlePath, circlePaint); } public boolean onTouch(View view, MotionEvent event) { x = (int) event.getX(); y = (int) event.getY(); bitmapCanvas.drawCircle(x, y, 30, eraserPaint); circlePath.reset(); circlePath.addCircle(x, y, 30, Path.Direction.CW); int ac=event.getAction(); switch(ac){ case MotionEvent.ACTION_UP: Toast.makeText(MainActivity.this, String.valueOf(x), Toast.LENGTH_SHORT).show(); circlePath.reset(); break; } invalidate(); return true; } } } 

    consulte Mais informação

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.