I need to crop a Bitmap, but instead of having a rectangular cropped image (which I managed successfully to do), I need it to be any form defined by coordinates.
I'm following the answer from this thread: Cutting a multipoint ploygon out of Bitmap and placing it on transparency , and trying to implement it, but unfortunatly it does not clip the image.
I did as in the description, but it seems there's a bug somewhere. The image is drawn in rectangular way. Am I missing something?
Bitmap originalBitmap=BitmapFactory.decodeResource(getResources(), R.drawable.test_image);
// Image cropped
Bitmap croppedBitmap=Bitmap.createBitmap(originalBitmap, 10, 10, 200, 200);
Canvas canvas=new Canvas(croppedBitmap);
// Create a path
Path path=new Path();
path.setFillType(FillType.INVERSE_EVEN_ODD);
path.moveTo(0, 0);
path.moveTo(0, 100);
path.moveTo(100, 0);
path.moveTo(0, 0);
// Paint with Xfermode
Paint paint=new Paint();
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
// Draw the path
canvas.drawPath(path, paint);
imageView.setImageBitmap(croppedBitmap);