How to create white border around bitmap?

后端 未结 8 1893
萌比男神i
萌比男神i 2021-02-12 19:24

For example I want a white border of 10pixel around all 4 side of the bitmap. I am not using it for imageview I am currently using this code to crop image. May I know how I coul

8条回答
  •  旧巷少年郎
    2021-02-12 19:34

    As for a way of doing this. You make your bitmap bigger than the one your adding to it and then fill the canvas with the background you want. If you need to add other effects you can look into the canvas options for clipping the rect and adding rounded corners and such.

    RectF targetRect = new RectF(left+10, top+10, left + scaledWidth, top + scaledHeight);
    Bitmap dest = Bitmap.createBitmap(newWidth+20, newHeight+20, source.getConfig());
    Canvas canvas = new Canvas(dest);
    canvas.drawColor(Color.WHITE);
    canvas.drawBitmap(source, null, targetRect, null);
    

提交回复
热议问题