Drawing an outer shadow when drawing an image

后端 未结 4 1734
无人共我
无人共我 2020-11-30 07:10

I currently create a rounded version of an image in my app by drawing to a canvas. I would like to draw a faint outershadow around the image, but I cant quite get it right.

4条回答
  •  青春惊慌失措
    2020-11-30 07:25

    Create a xml name it round_shape.xml in drawable folder

    
    
    
        
    
    

    Set this round_shape as back ground of image view like below

    
    

    The above code create a thin layer around image view after you have round the bitmap , below function will do this

    public Bitmap roundBit(Bitmap bm) {
    
            Bitmap circleBitmap = Bitmap.createBitmap(bm.getWidth(),
                    bm.getHeight(), Bitmap.Config.ARGB_8888);
    
            BitmapShader shader = new BitmapShader(bm, TileMode.CLAMP,
                    TileMode.CLAMP);
            Paint paint = new Paint();
            paint.setShader(shader);
            paint.setAntiAlias(true);
            Canvas c = new Canvas(circleBitmap);
            c.drawCircle(bm.getWidth() / 2, bm.getHeight() / 2, bm.getWidth() / 2,
                    paint);
    
            return circleBitmap;
    }
    

提交回复
热议问题