Android: padding left a bitmap with white color

后端 未结 5 685
情话喂你
情话喂你 2020-12-16 14:30

How to set all white the 10 rows on the left side of a Bitmap? I\'v got a Bitmap that has to be padded on the left side. I thought i can create a new image iterate on the ol

5条回答
  •  一生所求
    2020-12-16 15:20

    You can instead create a new Bitmap with the extra padding number of pixels. Set this as the canvas bitmap and Color the entire image with the required color and then copy your bitmap.

    public Bitmap pad(Bitmap Src, int padding_x, int padding_y) {
        Bitmap outputimage = Bitmap.createBitmap(Src.getWidth() + padding_x,Src.getHeight() + padding_y, Bitmap.Config.ARGB_8888);
        Canvas can = new Canvas(outputimage);
        can.drawARGB(FF,FF,FF,FF); //This represents White color
        can.drawBitmap(Src, padding_x, padding_y, null);
        return outputimage;
    }
    

提交回复
热议问题