Making an image circular with white circular border

后端 未结 10 2471
甜味超标
甜味超标 2021-02-19 19:32

How to make an image circular and give it white circular border? Is it necessary to use two image views – one for the image and other for the white border? Is there any other wa

10条回答
  •  别跟我提以往
    2021-02-19 20:19

    Try This
        public static Bitmap createRoundImage(Bitmap loadedImage) {
        System.out.println("loadbitmap" + loadedImage);
        loadedImage = Bitmap.createScaledBitmap(loadedImage, 100, 100, true);
        Bitmap circleBitmap = Bitmap.createBitmap(loadedImage.getWidth(),
                loadedImage.getHeight(), Bitmap.Config.ARGB_8888);
        BitmapShader shader = new BitmapShader(loadedImage,
                Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setShader(shader);
    
        Canvas c = new Canvas(circleBitmap);
        c.drawCircle(loadedImage.getWidth() / 2, loadedImage.getHeight() / 2,
                loadedImage.getWidth() / 2, paint);
        return circleBitmap;
    }
    

提交回复
热议问题