Crop image / pull to triangle

I am trying to crop the image into a triangle in my Android application, so that I only get the triangular part of the image. How can this be done? I have successfully cropped Square and Circle shapes, but I can't do the same for the triangle. Can anyone help me with this.

Thanks.

David

0
source share
1 answer

You can use the "Mask" image. This image should be a triangle in your case (or any other shape you need) as follows:

ImageView mImageView= (ImageView)findViewById(R.id.imageview_id); Bitmap original = BitmapFactory.decodeResource(getResources(),R.drawable.contentimage); Bitmap mask = BitmapFactory.decodeResource(getResources(),R.drawable.mask); Bitmap result = Bitmap.createBitmap(mask.getWidth(), mask.getHeight(), Config.ARGB_8888); Canvas mCanvas = new Canvas(result); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); mCanvas.drawBitmap(original, 0, 0, null); mCanvas.drawBitmap(mask, 0, 0, paint); paint.setXfermode(null); mImageView.setImageBitmap(result); mImageView.setScaleType(ScaleType.CENTER); mImageView.setBackgroundResource(R.drawable.background_frame); 
0
source

All Articles