title: How to add padding completely around a bitmap programmatically?
body: <p>I'm trying to add padding to a bitmap programmatically however, when I add the padding to the top, it's removed from the bottom. When I add it to the bottom, it's removed from the top.</p>
  <p>Adding padding to the top</p>
  <p><a href="https://i.stack.imgur.com/EsGNG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EsGNG.png" alt="enter image description here" /></a></p>
  <pre><code>Bitmap backgroundBitmap = ((BitmapDrawable) backgroundDrawable).getBitmap();
  
  
              int padding = 60;
  
              int positionLeft = 0;
              int positionTop = 0;
              Bitmap mainBitmap = Bitmap.createBitmap(
                      backgroundBitmap.getWidth(), //Adding top padding here
                      backgroundBitmap.getHeight() + padding,
                      Bitmap.Config.ARGB_8888
              );
              Canvas canvas = new Canvas(mainBitmap);
              canvas.drawBitmap(
                      backgroundBitmap,
                      positionLeft + padding,
                      positionTop + padding,
                      null
              );
  </code></pre>
  <p>Adding padding to the bottom removes the top padding</p>
  <pre><code> Bitmap backgroundBitmap = ((BitmapDrawable) backgroundDrawable).getBitmap();
  
  
              int padding = 60;
  
              int positionLeft = 0;
              int positionTop = 0;
              Bitmap mainBitmap = Bitmap.createBitmap(
                      backgroundBitmap.getWidth(),
                      backgroundBitmap.getHeight() + padding,
                      Bitmap.Config.ARGB_8888
              );
              Canvas canvas = new Canvas(mainBitmap);
              canvas.drawBitmap(
                      backgroundBitmap,
                      positionLeft + padding,
                      positionTop, //Adding bottom padding here
                      null
              );
  </code></pre>
  <p><a href="https://i.stack.imgur.com/hj4ep.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hj4ep.png" alt="enter image description here" /></a></p>
  <p>Can't figure out</p>
  <p>how can I add padding to all 4 sides to my <code>backgroundBitmap</code> bitmap?</p>
  <p><strong>Edit1:____________________________________________</strong></p>
  <p>I've also tried this solution:</p>
  <p><a href="https://stackoverflow.com/a/15525394/11110509">https://stackoverflow.com/a/15525394/11110509</a></p>
  <p>which adds a border to the bitmap, however it's only adding the border to the top and left. Doesn't include the bottom and right</p>
  <pre><code>private Bitmap addWhiteBorder(Bitmap bmp, int borderSize) {
      Bitmap bmpWithBorder = Bitmap.createBitmap(bmp.getWidth() + borderSize * 2, bmp.getHeight() + borderSize * 2, bmp.getConfig());
      Canvas canvas = new Canvas(bmpWithBorder);
      canvas.drawColor(Color.BLUE);
      canvas.drawBitmap(bmp, borderSize, borderSize, null);
      return bmpWithBorder;
  }
  </code></pre>
  <pre><code>Bitmap backgroundBitmap = ((BitmapDrawable) backgroundDrawable).getBitmap();
  
  
              int padding = 60;
  
              int positionLeft = 0;
              int positionTop = 0;
              Bitmap mainBitmap = Bitmap.createBitmap(
                      backgroundBitmap.getWidth(),
                      backgroundBitmap.getHeight(),
                      Bitmap.Config.ARGB_8888
              );
              Canvas canvas = new Canvas(mainBitmap);
              canvas.drawBitmap(
                      addWhiteBorder(backgroundBitmap, padding),
                      positionLeft,
                      positionTop,
                      null
              );
  </code></pre>
  <p><a href="https://i.stack.imgur.com/ukxwi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ukxwi.png" alt="enter image description here" /></a></p>