I try to crop the image and then rotate it in the corners so that it looks more beautiful on the screen.
What I managed to do is round the corners of the image, but cropping will sometimes crop the sides of the image (depending on the size / proportion of the image).
So, what I would like to do is complete the crop, then apply rounded corners. How can i do this?
Rounding the corners of the image:
private Bitmap getRoundedCornerBitmap(Bitmap bitmap) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff000000; final Paint paint = new Paint(); final Rect rect = new Rect(0,0,bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); final float roundpx = 20; paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundpx, roundpx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
And then I set the image scaling type like this: imageView.setScaleType(ScaleType.CENTER_CROP)
source share