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

  • Home
  • SEARCH
  • 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 3941552
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:33:24+00:00 2026-05-20T00:33:24+00:00

I am trying to composite a background bitmap from multiple smaller bitmaps. I am

  • 0

I am trying to composite a background bitmap from multiple smaller bitmaps. I am using Eclipse with the Android SDK.

I have loaded a (mostly) blank background bitmap (pixel dimensions are 320×480) like so:

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

Then I load a bitmap ’tile’ (128×128) the same way.

I have tried multiple ways of drawing the tile onto the bitmap but every single method does not work the way I would like/expect. I want to draw the tile bitmap scaled down to 64×64 and at a specific location (pixel offset) on the background bitmap.

1) Using a Canvas…

Canvas c = new Canvas( mBackground );
c.drawBitmap( mTile, null, new Rect( 10, 10, 73, 73 ), null );

This draws the tile way too big (not fullsize, not 64×64, but somewhere in between, about 66% of original)

2) Using drawables (which basically seems to be the same):

Canvas c = new Canvas( mBackground );
c.translate( 10, 10 );
d.setBounds( 0, 0, 63, 63 );
d.draw( c );

Same result as experiment #1…

The documentation mentions in numerous places (without a concise explanation anywhere) that this has to do with the device independent ‘densities’ thus I tried the next approach…

3) Using fixed scale resources. I created the /res/drawable-nodpi (I also tried just /res/drawable) folder and moved my resources (background and tile png images) into it. That causes an exception when creating the Canvas from the background Bitmap because an unscaled bitmap apparently becomes immutable and therefore cannot be assigned to a Canvas!

4) I tried using BitmapFactory.Options and setting inScaled to false, and passing those options to both of the decodeResource calls for the background and the tile. This has the exact same effect as #3 (exception thrown).

Nothing has worked and its becoming quite frustrating. I am sure I am just missing some detail that is peculiar to bitmaps when it comes to the different coordinate spaces but I cannot find it anywhere in the documentation or elsewhere (I’ve tried multiple android development sites to no avail).

Hopefully someone who has done this will see this plea!
Thanks, jason

  • 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-05-20T00:33:24+00:00Added an answer on May 20, 2026 at 12:33 am

    Canvas.drawBitmap() does not perform scaling afaik.

    Since your tile image is originally 128×128 and you want to draw it at 64×64, the simplest trick would be to call decodeResource() with the option to reduce it in size:

    BitmapFactory.Options options = new BitmapFactory.Options()
    options.inSampleSize = 2; // downscale by 50%
    Bitmap mTile = BitmapFactory.decodeResource( res, R.drawable.tile, options );
    

    To do more powerful scaling (e.g. drawing your image at any size) you should wrap it in a BitmapDrawable.

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

Sidebar

Related Questions

I'm trying to avoid a composite control or using and ASCX by extending an
I am trying to modify a mass storage driver using the composite usb framework
i'm trying to remove an item from a one to many list and have
I'm trying to get a composite component working with it's own backing bean, using
I'm trying to map a ManyToMany relationships between 2 tables, both having composite primary
Trying to write a python application that downloads images from an RSS feed, and
I have two ImageButtons, and I am trying to stack one on top of
I am learning java. I am trying to use composite design pattern. I am
I'm trying to add a composite primary key to a class and having a
I am trying to create a composite key that mimicks the set of PrimaryKeys

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.