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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:37:42+00:00 2026-05-23T09:37:42+00:00

I am trying to scale my images down to smaller size I was loading

  • 0

I am trying to scale my images down to smaller size I was loading them as they were into an imageview and I started getting a “bitmap size exceeds VM budget” exception. On the other hand if I get the thumbnails instead of the actual images and show them it runs smooth. But I need the URIs of the actual images for later use which I can’t get if I straight away load the thumbnails.

After looking around, I found a way, but it’s not working.

Code:

Uri uri = Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, name);
uriList.add(uri.getPath());

File image = new File(uri.getPath());

BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;
Bitmap actualBitmap = BitmapFactory.decodeFile(image.getPath(), options);
Bitmap scaledBitmap = Bitmap.createScaledBitmap(actualBitmap, image_width, image_height, false);
iv.setImageBitmap(scaledBitmap);

The part where I get the actualBitmap returns null, and so the imageview is empty. If I print uri.getpath() it gives:

/external/images/media//sdcard/dcim/Camera/imagename.jpg

My question is, is this the right approach? If it is, what am I doing wrong and if it’s not can someone please point me in the right direction.

  • 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-23T09:37:42+00:00Added an answer on May 23, 2026 at 9:37 am

    try with the following code

    public static Bitmap resizeBitMapImage1(String filePath, int targetWidth,
                int targetHeight) {
            Bitmap bitMapImage = null;
            // First, get the dimensions of the image
            Options options = new Options();
            options.inJustDecodeBounds = true;
            BitmapFactory.decodeFile(filePath, options);
            double sampleSize = 0;
            // Only scale if we need to
            // (16384 buffer for img processing)
            Boolean scaleByHeight = Math.abs(options.outHeight - targetHeight) >= Math
                    .abs(options.outWidth - targetWidth);
    
            if (options.outHeight * options.outWidth * 2 >= 1638) {
                // Load, scaling to smallest power of 2 that'll get it <= desired
                // dimensions
                sampleSize = scaleByHeight ? options.outHeight / targetHeight
                        : options.outWidth / targetWidth;
                sampleSize = (int) Math.pow(2d,
                        Math.floor(Math.log(sampleSize) / Math.log(2d)));
            }
    
            // Do the actual decoding
            options.inJustDecodeBounds = false;
            options.inTempStorage = new byte[128];
            while (true) {
                try {
                    options.inSampleSize = (int) sampleSize;
                    bitMapImage = BitmapFactory.decodeFile(filePath, options);
    
                    break;
                } catch (Exception ex) {
                    try {
                        sampleSize = sampleSize * 2;
                    } catch (Exception ex1) {
    
                    }
                }
            }
    
            return bitMapImage;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to scale an ImageView down in an animation, but whenever I
I'm trying to create a scale functionality for certain images when they are hovered,
I am trying to load images quickly into a picturebox and draw on them.
I'm trying to get every widget to scale with change in window size. I
I am trying to reduce the size of images retrieved form the camera (so
i am trying to scale down a image i get from photo library on
I am trying to composite a background bitmap from multiple smaller bitmaps. I am
I am trying to scale images to fit within their parent element width, and
I'm trying to scale an image down, change the image, then scale it back
I'm trying to get started with Scala and cannot get out of the starting

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.