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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:11:59+00:00 2026-06-13T02:11:59+00:00

In my application I am going to be loading and displaying various images from

  • 0

In my application I am going to be loading and displaying various images from a server, and there’s no limit to how big each one can be. I’ve already fought my battles with the various issues of Bitmap memory usage in Android that so many people have complained about here, and I’ve got that much working in that old bitmaps are being released and recycled when I’m done with them. My issue now is the possibility of a single enormous image exceeding the memory allocation all by itself. I’ve already looked into the various options for downsizing images to conserve memory and get how all that works – my issue is that I would like to preserve image quality as much as possible, so I would like the Bitmap to use as much memory as it can without killing everything.

So, my question is, given that there is such a wide variety of devices with different memory capacities, is there any way to determine a suitable maximum size at runtime in order to balance memory allocation with image quality?

  • 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-13T02:12:00+00:00Added an answer on June 13, 2026 at 2:12 am

    I found myself with similar issues. After some research and testing I came up with a number of methods that helped me on that subject. Those are implemented with C# using Mono for Android but I guess they should be almost identical with Java:

    /// <summary>
    ///Calculates the memory bytes used by the given Bitmap.
    /// </summary>
    public static long GetBitmapSize(Android.Graphics.Bitmap bmp)
    {
      return GetBitmapSize(bmp.Width, bmp.Height, bmp.GetConfig());
    }
    
    /// <summary>
    ///Calculates the memory bytes used by a Bitmap with the given specification.
    /// </summary>
    public static long GetBitmapSize(long bmpwidth, long bmpheight, Android.Graphics.Bitmap.Config config)
    {
      int BytesxPixel = (config == Android.Graphics.Bitmap.Config.Rgb565) ? 2 : 4;
    
      return bmpwidth * bmpheight * BytesxPixel;
    }
    
    /// <summary>
    ///Calculates the memory available in Android's VM.
    /// </summary>
    public static long FreeMemory()
    {
      return Java.Lang.Runtime.GetRuntime().MaxMemory() - Android.OS.Debug.NativeHeapAllocatedSize;
    }
    
    /// <summary>
    ///Checks if Android's VM has enough memory for a Bitmap with the given specification.
    /// </summary>
    public static bool CheckBitmapFitsInMemory(long bmpwidth, long bmpheight, Android.Graphics.Bitmap.Config config)
    {
      return (GetBitmapSize(bmpwidth, bmpheight, config) < FreeMemory());
    }
    

    That code proved pretty reliable preventing out of memory exceptions. An example using those methods in the namespace called Utils is the code snippet below. This code calculates the memory necessary for 3 bitmaps, two of them being 3 times as big as the first one.

    /// <summary>
    /// Checks if there's enough memory in the VM for managing required bitmaps.
    /// </summary>
    private bool NotEnoughMemory()
    {
      long bytes1 = Utils.GetBitmapSize(this.Width, this.Height, BitmapConfig);
      long bytes2 = Utils.GetBitmapSize(this.Width * 3, this.Height * 3, BitmapConfig);
    
      return ((bytes1 + bytes2 + bytes2) >= Utils.FreeMemory());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I stop my application from going back when the user clicks on
In my application there are going to be lots of users, over 500. They
I'm developing a web application that is going to be served from an OSGi
I am loading a map of values into ServletContext during start of the application/server
I'm beginning going crazy with extjs4 and form loading. In my struts application, I
I have an application where, in one window, there is an NSImageView. The user
I've got a C# application going that needs to send out an html email
I am writing an application which is going to allows users to change the
I have an application that is going to work like a p2p-software where all
I have an application which is going to be distributed to a hosting platform,

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.