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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:06:50+00:00 2026-05-17T01:06:50+00:00

Say I have a somewhat large (i.e. not fit in most phones’ memory) bitmap

  • 0

Say I have a somewhat large (i.e. not fit in most phones’ memory) bitmap on disk. I want to draw only parts of it on the screen in a way that isn’t scaled (i.e. inSampleSize == 1)

Is there a way to load/draw just the part I want given a Rect specifying the area without loading the entire bitmap content?

  • 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-17T01:06:51+00:00Added an answer on May 17, 2026 at 1:06 am

    I’m quite confident this is possible since you can load a really large bitmap file into an ImageView without problems so there must be some sort of a built-in way to handle large bitmaps… and after a few attempts, I’ve found a solution:

    Instead of loading the entire bitmap and manually draw it yourself, load it as a Drawable instead:

    InputStream mapInput = getResources().openRawResource(
            R.drawable.transit_map);
    _map = Drawable.createFromStream(mapInput, "transit_map");
    
    _map.setBounds(0, 0, _mapDimension.width(), _mapDimension.height());
    

    I’m using a resource file but since you can use Drawable.createFromStream to load image from any InputStream, it should works with arbitrary bitmap.

    Then, use the Drawable.draw method to draw it onto the desired canvas like so:

    int left = -(int) contentOffset.x;
    int top = -(int) contentOffset.y;
    int right = (int) (zoom * _mapDimension.width() - contentOffset.x);
    int bottom = (int) (zoom * _mapDimension.height() - contentOffset.y);
    
    _map.setBounds(left, top, right, bottom);
    _map.draw(canvas);
    

    As in the above case, You can also scale and translate the bitmap as well by manipulating the drawable’s bounds and only the relevant parts of the bitmap will be loaded and drawn onto the Canvas.

    The result is a pinch-zoomable view from just one single 200KB bitmap file. I’ve also tested this with a 22MB PNG file and it still works without any OutOfMemoryError including when screen orientation changes.

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

Sidebar

Related Questions

I am somewhat new to LINQ and have a quick question regarding deleting. Say,
Say I have a class, something like the following; class MyClass { public: MyClass();
In fairly large Ruby application, we have a situation where a given object is
I am embarking upon a NLP project for sentiment analysis. I have successfully installed
I have a C++ library that generates much larger code that I would really
I have a subversion repository with the standard layout, i.e. trunk/ and branches/ (and
We're developing a large desktop application using Windows Presentation Foundation. Currently, the application is
I'm a software test engineer embedded in a development team. A large part of
I'm storing a set of messages in a SQL table. Each message has a
I'm relatively well versed in designing websites. I mostly go for LAMP where I

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.