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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:06:19+00:00 2026-06-18T22:06:19+00:00

i am loading some bitmap from the gallery using the following code: bitmap =

  • 0

i am loading some bitmap from the gallery using the following code:

 bitmap = (BitmapFactory.decodeFile(picturePath)).copy(Bitmap.Config.ARGB_8888, true);
 bitmap = Bitmap.createScaledBitmap(bitmap, screenWidth, screenHeight, true);
 bitmapCanvas = new Canvas(bitmap);
 invalidate(); // refresh the screen

Question:

It seems that it takes so long time to load an image by first decode fully and copy, and then making scaling to fit for the screen width and height. It really actually does not need to load the pic with full density because I would not let the user to enlarge the imported image anyway.

In that way, are there any method to reduce the load time and RAM? (directly load a scaled-down image) How to further modify the above coding?

  • 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-18T22:06:20+00:00Added an answer on June 18, 2026 at 10:06 pm

    just have found the answer for this reducing RAM and load time and avoid outofmemory error from other similar questions.

    //get importing bitmap dimension
       Options op = new Options();
       op.inJustDecodeBounds = true;
       Bitmap pic_to_be_imported = BitmapFactory.decodeFile(picturePath, op);
       final int x_pic = op.outWidth;
       final int y_pic = op.outHeight;
    
    //The new size we want to scale to
        final int IMAGE_MAX_SIZE= (int) Math.max(DrawViewWidth, DrawViewHeight);
    
        int scale = 1;
        if (op.outHeight > IMAGE_MAX_SIZE || op.outWidth > IMAGE_MAX_SIZE) 
        {
            scale = (int)Math.pow(2, (int) Math.round(Math.log(IMAGE_MAX_SIZE / 
                   (double) Math.max(op.outHeight, op.outWidth)) / Math.log(0.5)));
        }
    
        final BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize = scale;        
    
    //Import the file using the o2 options: inSampleSized
        bitmap = (BitmapFactory.decodeFile(picturePath, o2));
        bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am loading some template files into my application using require.js like so: define(function(require)
In my application, I'm loading some data from a file. This can fail and
Simply what it says on the tin I'm loading a bitmap from a file
I'm loading my bitmaps with preferred config RGB565 from my assets folder and logging
I'm loading a DIBSection from a file with the following: HBITMAP bmpIn = (HBITMAP)
I'm loading a big jpeg file from a url using an InputStream from a
I'm loading some HTML via Ajax with this format: <div id=div1> ... some content
I'm loading some feeds and displaying them as links on my site page. When
I am loading some text dynamically into a div, but have the problem that
Summary of the issue: When I am loading some data into my iPhone application

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.