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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:43:23+00:00 2026-06-14T13:43:23+00:00

I want go get image from URL and convert it into drawable. I have

  • 0

I want go get image from URL and convert it into drawable. I have this method, that works fine:

public static Drawable getDrawableFromUrl(String url) throws IOException {
    Bitmap x;

    HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
    connection.connect();
    InputStream input = connection.getInputStream();

    x = BitmapFactory.decodeStream(input);
    return new BitmapDrawable(x);
}

Except one thing. When image is too big app crashes.

E/dalvikvm-heap(12750): 13142360-byte external allocation too large for this process.
E/dalvikvm(12750): Out of memory: Heap Size=6023KB, Allocated=3177KB, Bitmap Size=2563KB, Limit=20480KB
E/dalvikvm(12750): Trim info: Footprint=6023KB, Allowed Footprint=6023KB, Trimmed=952KB
E/GraphicsJNI(12750): VM won't let us allocate 13142360 bytes

Can I somehow increase the memory that I need for the image? Or maybe there is a way around this problem?

  • 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-14T13:43:24+00:00Added an answer on June 14, 2026 at 1:43 pm

    Ok. Here is the code that finaly works.
    As suggested I reduced the size of image using given function: calculateInSampleSize – thx Androyds.

    public static Drawable getDrawableFromUrl(String url, Context context) throws IOException {
        Bitmap x;
    
        HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
        connection.connect();
        InputStream inputStream = connection.getInputStream();
        BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
    
        BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    bufferedInputStream.mark(connection.getContentLength());
    BitmapFactory.decodeStream(bufferedInputStream, null, options);
    bufferedInputStream.reset();
    
    options.inJustDecodeBounds = false;
    options.inSampleSize = calculateInSampleSize(options, 400, 400);
    
    x = BitmapFactory.decodeStream(bufferedInputStream, null, options);
    
    bufferedInputStream.close();
    connection.disconnect();
    
        BitmapDrawable y = new BitmapDrawable(x);
    
        return y;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string of my url.. I want to get data from that
I have this bit of code that get the image i have picked from
i want to get a remote JPG file from a URL and have it
The url is: https://api.url2png.com/v3/P4DE5D1C99D8EF/7bbb6e0d1b74fb0ae1d4f18b06320096/400x400/abc.com I want to get above image into to a UIImage.
Using Paperclip, I want to grab an image from a URL like this: require
I want to get the Bitmap from URL like - https://graph.facebook.com/100003506521332/picture I tried how-i-can-display-images-from-url-in-blackberry
I want just get Image( .JPG , .PNG , .Gif ) File from my
I want to get a thumbnail image for videos from Vimeo. When getting images
I want to get this image uploading script right, but for whatever reason it
Hi i want to get image faster from website in iphone.. Now i get

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.