Android: padding left a bitmap with white color

How to set all white 10 lines on the left side of a bitmap? I have a bitmap that needs to be padded on the left. I thought I could create a new image, iterate on the old getpixel for each position and setpixel on the new (white or color) than returning a new bitmap ... is this wrong? Any suggestion? thanks a lot!

+6
source share
3 answers

Instead, you can create a new bitmap with an extra pixel count. Set this as a canvas bitmap and color the entire image with the desired color, and then copy the 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; } 
+16
source

You can look here:

http://download.oracle.com/javase/1.4.2/docs/api/java/awt/image/BufferedImage.html

which you might want to use: getHeight (), then you know how many pixels you need to set and iterate over 10 columns.

and setRGB (int x, int y, int RGB) to set the pixel

0
source
 public Bitmap addPaddingTopForBitmap(Bitmap bitmap, int paddingTop) { Bitmap outputBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight() + paddingTop, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(outputBitmap); canvas.drawColor(Color.RED); canvas.drawBitmap(bitmap, 0, paddingTop, null); return outputBitmap; } public Bitmap addPaddingBottomForBitmap(Bitmap bitmap, int paddingBottom) { Bitmap outputBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight() + paddingBottom, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(outputBitmap); canvas.drawColor(Color.RED); canvas.drawBitmap(bitmap, 0, 0, null); return outputBitmap; } public Bitmap addPaddingRightForBitmap(Bitmap bitmap, int paddingRight) { Bitmap outputBitmap = Bitmap.createBitmap(bitmap.getWidth() + paddingRight, bitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(outputBitmap); canvas.drawColor(Color.RED); canvas.drawBitmap(bitmap, 0, 0, null); return outputBitmap; } public Bitmap addPaddingLeftForBitmap(Bitmap bitmap, int paddingLeft) { Bitmap outputBitmap = Bitmap.createBitmap(bitmap.getWidth() + paddingLeft, bitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(outputBitmap); canvas.drawColor(Color.RED); canvas.drawBitmap(bitmap, paddingLeft, 0, null); return outputBitmap; } 
0
source

Source: https://habr.com/ru/post/894382/


All Articles