让图片(ImageView)的某一个角为圆角

    public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) {

        Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
                bitmap.getHeight(), Config.ARGB_8888);
        Canvas canvas = new Canvas(output);
        final int color = 0xff424242;
        final Paint paint = new Paint();
        path = new Path();
        final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
        final RectF rectF = new RectF(rect);
        paint.setAntiAlias(true);
        canvas.drawARGB(0, 0, 0, 0);
        paint.setColor(color);
        //画出4个圆角的矩形
//        canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
       
        //根据四个角的信息分别画各个角的圆角形状
        float[] radii = { 100f, 100f, 50f, 50f, 0f, 0f, 0f, 0f };
        path.addRoundRect(rectF, radii, Path.Direction.CW);
        canvas.drawPath(path, paint);
//        canvas.drawArc(rectF, 0, 90, false, paint);
        paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
        canvas.drawBitmap(bitmap, rect, rect, paint);
        return output;
    }

你可能感兴趣的:(让图片(ImageView)的某一个角为圆角)