CopyPastor

Detecting plagiarism made easy.

Score: 0.8459013104438782; Reported for: String similarity Open both answers

Possible Plagiarism

Reposted on 2017-03-21
by Daniel Nyamasyo

Original Post

Original - Posted on 2017-03-21
by Daniel Nyamasyo



            
Present in both answers; Present only in the new answer; Present only in the old answer;

Can you try this solution it will help you with the erasing images in android on touch .. Or download a [**demo example**][1]

[1]: http://whats-online.info/science-and-tutorials/137/Android-tutorial-How-to-erase-part-of-bitmap-image-on-touch/
public class MainActivity extends Activity { Bitmap bp; Canvas bitmapCanvas; DrawView drawImg; LinearLayout ln1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ln1 = (LinearLayout) 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); } @Override 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; } } }

Here is another advancement for your solution ... [**See Demo example**][1]

public class MainActivity extends Activity { Bitmap bp; Canvas bitmapCanvas; DrawView drawImg; LinearLayout ln1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ln1 = (LinearLayout) 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); } @Override 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; } } }
[read more][1]

[1]: http://whats-online.info/science-and-tutorials/137/Android-tutorial-How-to-erase-part-of-bitmap-image-on-touch/

        
Present in both answers; Present only in the new answer; Present only in the old answer;