ImageView rounded corners

后端 未结 17 1993
长发绾君心
长发绾君心 2020-11-27 15:33

I wanted image to have rounded corners. I implement this xml code and use this in my image view. but image overlap the shape. I am downloading the image through async task.<

17条回答
  •  执笔经年
    2020-11-27 16:13

    its simple as possible by using this util method

    /*
     * param@ imageView is your image you want to bordered it
     */
    public static Bitmap generateBorders(ImageView imageView){
        Bitmap mbitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
        Bitmap imageRounded = Bitmap.createBitmap(mbitmap.getWidth(), mbitmap.getHeight(), mbitmap.getConfig());
        Canvas canvas = new Canvas(imageRounded);
        Paint mpaint = new Paint();
        mpaint.setAntiAlias(true);
        mpaint.setShader(new BitmapShader(mbitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
        canvas.drawRoundRect((new RectF(0, 0, mbitmap.getWidth(), mbitmap.getHeight())), 100, 100, mpaint);// Round Image Corner 100 100 100 100
        return imageRounded;
    }
    

    then set your image view bitmap with returned value have fun

提交回复
热议问题