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 7892195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:48:33+00:00 2026-06-03T06:48:33+00:00

The following code defines my Bitmap: Resources res = context.getResources(); mBackground = BitmapFactory.decodeResource(res, R.drawable.background);

  • 0

The following code defines my Bitmap:

Resources res = context.getResources();

mBackground = BitmapFactory.decodeResource(res, R.drawable.background);

// scale bitmap
int h = 800; // height in pixels
int w = 480; // width in pixels
// Make sure w and h are in the correct order
Bitmap scaled = Bitmap.createScaledBitmap(mBackground, w, h, true);

… And the following code is used to execute/draw it (the unscaled Bitmap):

canvas.drawBitmap(mBackground, 0, 0, null);

My question is, how might I set it to draw the scaled Bitmap returned in the form of Bitmap scaled, and not the original?

  • 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-03T06:48:34+00:00Added an answer on June 3, 2026 at 6:48 am

    Define a new class member variable:
    Bitmap mScaledBackground;
    Then, assign your newly created scaled bitmap to it:
    mScaledBackground = scaled;
    Then, call in your draw method:
    canvas.drawBitmap(mScaledBackground, 0, 0, null);

    Note that it is not a good idea to hard-code screen size in the way you did in your snippet above. Better would be to fetch your device screen size in the following way:

    int width = getWindowManager().getDefaultDisplay().getWidth();
    int height = getWindowManager().getDefaultDisplay().getHeight();
    

    And it would be probably better not to declare a new bitmap for the only purpose of drawing your original background in a scaled way. Bitmaps consume a lot of precious resources, and usually a phone is limited to a few MB of Bitmaps you can load before your app ungracefully fails. Instead you could do something like this:

    Rect src = new Rect(0, 0, bitmap.getWidth() - 1, bitmap.getHeight() - 1);
    Rect dest = new Rect(0, 0, width - 1, height - 1);
    canvas.drawBitmap(mBackground, src, dest, null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code works fine #define open { #define close } #include<stdio.h> #define int
I have the following code. // mfc.cpp : Defines the entry point for the
The following code defines two classes ( DeckA and DeckB ) that differ only
in java, the following code defines an array of the predefined class ( myCls
i am using the following code for form action, // includes require_once('inc/mysql_wrapper.php'); $DB=get_db_connection(); require_once('inc/defines.inc.php');
Suppose you have the following code: int main(int argc, char** argv) { Foo f;
The following code defines a hash with regular expressions (keys) and replacements (values). Then
Consider the following code // BOGP.cpp : Defines the entry point for the console
I recently noticed the following code which basically defines a class method public Func<string,
I've got the following Delphi code that defines a set and then a simple

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.