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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:30:10+00:00 2026-05-28T14:30:10+00:00

How can I load drawable from InputStream (assets, file system) and resize it dynamically

  • 0

How can I load drawable from InputStream (assets, file system) and resize it dynamically based on the screen resolution hdpi, mdpi or ldpi?

The original image is in hdpi, I only need resizing for mdpi and ldpi.

How does Android do dynamic resizing of the drawables in /res?

  • 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-28T14:30:11+00:00Added an answer on May 28, 2026 at 2:30 pm

    Found it:

      /**
       * Loads image from file system.
       * 
       * @param context the application context
       * @param filename the filename of the image
       * @param originalDensity the density of the image, it will be automatically
       * resized to the device density
       * @return image drawable or null if the image is not found or IO error occurs
       */
      public static Drawable loadImageFromFilesystem(Context context, String filename, int originalDensity) {
        Drawable drawable = null;
        InputStream is = null;
    
        // set options to resize the image
        Options opts = new BitmapFactory.Options();
        opts.inDensity = originalDensity;
    
        try {
          is = context.openFileInput(filename);
          drawable = Drawable.createFromResourceStream(context.getResources(), null, is, filename, opts);         
        } catch (Exception e) {
          // handle
        } finally {
          if (is != null) {
            try {
              is.close();
            } catch (Exception e1) {
              // log
            }
          }
        }
        return drawable;
      }
    

    Use like this:

    loadImageFromFilesystem(context, filename, DisplayMetrics.DENSITY_MEDIUM);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can you load a drawable from a sub directory in the assets (not the
the php gd imagettftext function can only load true type fonts from a file.
I have: String uri = @drawable/myresource.png; How can I load that in ImageView? this.setImageDrawable?
Apache Pig can load data from Hadoop sequence files using the PiggyBank SequenceFileLoader :
I have a CSV of file of data that I can load in R
I am writing an app can load data from from web, then put the
I am able to load a resource image, from drawable folder, into a bitmap
I want to load array of Images one by one from drawable. At a
I can load COM DLLs that are registered on my machine like this: Type
I have a web application that can load plugins through reflection. It currently uses

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.