Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8475001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:46:40+00:00 2026-06-10T17:46:40+00:00

Is there any way to increase the width (or height) of a Bitmap without

  • 0

Is there any way to increase the width (or height) of a Bitmap without stretching it? Basically, I have a 200×100 bitmap and I want to make it square (200×200) by appending 50 (white / transparent) pixels to the left and 50 pixels to the right.

I don’t want to draw this Bitmap on the screen so, ideally, I should be using a transformation Matrix in a “smart” way or something like that, but I just can’t figure it out…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:46:42+00:00Added an answer on June 10, 2026 at 5:46 pm

    You may try something like this:

            // creating a dummy bitmap
            Bitmap source = Bitmap.createBitmap(100, 200, Bitmap.Config.ARGB_8888);
            Bitmap background;
            Canvas canvas;
    
            if(source.getHeight() == source.getWidth()) // do nothing
                return;
    
            // create a new Bitmap with the bigger side (to get a square)
            if(source.getHeight() > source.getWidth()) {
                background = Bitmap.createBitmap(source.getHeight(), source.getHeight(), Bitmap.Config.ARGB_8888);
                canvas = new Canvas(background);
                // draw the source image centered
                canvas.drawBitmap(source, source.getHeight()/4, 0, new Paint());
            } else {
                background = Bitmap.createBitmap(source.getWidth(), source.getWidth(), Bitmap.Config.ARGB_8888);
                canvas = new Canvas(background);
                // draw the source image centered
                canvas.drawBitmap(source, 0, source.getWidth()/4, new Paint());
            }
    
            source.recycle();
            canvas.setBitmap(null);
            // update the source image
            source = background;
    

    Note: The black border is not part of the image. I chose dark red as a background color to see the actual size of the image and to distinguish it from black and the source image’s color (which is always painted centered).

    By drawing it on a Canvas it is not visible on the screen. I used an ImageView just to test the code.

    Here is the output I get for w=200,h=100:

    enter image description here

    Here is the output I get for w=100,h=200:

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way by which I can increase the default width of the
Is there any way to resize (in my case increase the width) of an
Is there any way to increase the maximum time that a plugin can execute
Is there any way to increase the number of items in the iphone tab
Is there any way to change(increase) the data type of a column while saving
Is there any way in Notepad++ (or even with another tool) to change the
Is there any way I can set a formatter on models that will convert
Is there any way to use Google's API to retrieve a user's current zipcode
Is there any way to overload the > (greater than) operator, to be able
Is there any way we can fetch X509 Public Cetrificates using c# from AD

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.