Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to erase the last placed bitmap from a canvas with multiple bitmaps on it
    primarykey
    data
    text
    <p>I have a code in which,I am placing an Image on the canvas and tries to draw on it with Fingerpaint. But while I am using the Eraser to erase the last drawn lines or something with Fingerpaint, It is erasing the background image also...I am copying the code below.If you have any solution,please let me know.</p> <pre><code> @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); String pathName = Environment.getExternalStorageDirectory().toString()+"/test.jpg"; Bitmap image = LoadBMPsdcard(pathName); // Bitmap image = BitmapFactory.decodeResource(getResources(),R.drawable.hp).copy(Bitmap.Config.ARGB_8888, true); mBitmap = Bitmap.createScaledBitmap(image, sketchBoard.getWidth(), sketchBoard.getHeight(), true); //mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); mCanvas = new Canvas(mBitmap); } private Bitmap LoadBMPsdcard(String path) { //creates a 'File' object, to check if the image exists (Thanks to Jbeerdev for the tip) File imageFile = new File(path); //if the file exists if(imageFile.exists()) { //load the bitmap from the given path return BitmapFactory.decodeFile(path).copy(Bitmap.Config.ARGB_8888, true); } else { //return the standard 'Image not found' bitmap placed on the res folder return BitmapFactory.decodeResource(getResources(), R.drawable.imagenotfound).copy(Bitmap.Config.ARGB_8888, true); } } @Override protected void onDraw(Canvas canvas) { try{ canvas.drawColor(0x000FFF); //canvas.drawBitmap(mBitmap, srcRect, dstRect,mBitmapPaint); canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); canvas.drawPath(mPath, mPaint); }catch(Exception e){ e.printStackTrace(); } } </code></pre> <p>And the menu part that includes the eraser option is....</p> <pre><code>public boolean onOptionsItemSelected(MenuItem item) { mPaint.setXfermode(null); mPaint.setAlpha(0xFF); switch (item.getItemId()) { case R.id.newf: sketchBoard.removeAllViews(); view.invalidate(); view= new MyView(this); setContentView(view); return true; case R.id.red: // mPaint.reset(); mPaint.setColor(0xFF3300); mPaint.setAntiAlias(true); //view.invalidate(); return true; case R.id.white: // mPaint.reset(); mPaint.setColor(0xFFFFFF); mPaint.setAntiAlias(true); // view.invalidate(); return true; case R.id.blue: //mPaint.reset(); mPaint.setColor(0x0033FF); // view.invalidate(); return true; case R.id.save: cReatePNG(); return true; case R.id.eraser: mPaint.setXfermode(new PorterDuffXfermode( PorterDuff.Mode.CLEAR)); return true; case R.id.reset: sketchBoard.removeAllViews(); view.invalidate(); view= new MyView(this); setContentView(view); return true; case R.id.exit: finish(); } return super.onOptionsItemSelected(item); } </code></pre> <p>Thanks in Advance</p> <p>Arun</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload