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

  • Home
  • SEARCH
  • 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 7415651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:20:35+00:00 2026-05-29T07:20:35+00:00

I like to use the assets folder instead of the drawable folder (if it’s

  • 0

I like to use the assets folder instead of the drawable folder (if it’s not a nine-patch) because I can use multiple folders there. However the method I use to get an drawable required the cpu to do quiet a lot. For example: after adding 10 ImageViews need 10% CPU (I am using Android Assistent and Samsung TouchWiz TaskManager). I haven’t notice it while I was writing a game. And now this game needs 40-100% CPU even if it isn’t in the foreground.

That’s the method I use to create an drawable:

public BitmapDrawable readAsset(path){
    try{

        inputStream = assetManager.open(path);
        //get the Bitmap
        desiredImg = BitmapFactory.decodeStream(inputStream, null, opts);
        //resize for other screen sizes (scale is calculated beforehand)
        scaleX =(int)(desiredImg.getWidth()/scale);
        scaleY = (int)(desiredImg.getHeight()/scale);

        //Bitmap to get config ARGB_8888 (createScaledBitmap returns RGB_565 => bad quality especially in gradients)
        //create empty bitmap with Config.ARGB_8888 with the needed size for drawable
        Bitmap temp = Bitmap.createBitmap(scaleX, scaleY, Config.ARGB_8888);
        //Canvas to draw desiredImg on temp
        Canvas canvas = new Canvas(temp);
        canvas.drawBitmap(convert, null, new Rect(0, 0, scaleX, scaleY), paint);

        //Convert to BitmapDrawable
        BitmapDrawable bitmapDrawable=new BitmapDrawable(temp);
        bitmapDrawable.setTargetDensity(metrics);

        inputStream.close();
        return bitmapDrawable;
    }catch (Exception e) {
        Log.d(TAG, "InputStream failed: "+e.getMessage());
    }
    return null;
}

The only thing I do in the app is adding some ImageViews in a RelativeLayout with this method:

private void addImageToContainer(int paddingLeft, int paddingTop) {
    ImageView imageView = new ImageView(this);
    imageView.setImageDrawable(assetReader.readAsset("test.jpg"));
    imageView.setPadding(paddingLeft, paddingTop, 0, 0);
    container.addView(imageView);
}
  • 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-29T07:20:36+00:00Added an answer on May 29, 2026 at 7:20 am

    Probably the best thing for you to do would be to profile the execution with traceview, as this will give you a full understanding of where your app is spending most of its execution time. Then you can focus on optimizing that specific piece of code.

    Just an educated guess, but I have a feeling that the majority of the wasted execution is not because you are pulling the images out of assets/ instead of resources, but all the scaling work being done afterwards (and from the looks of it, this is all being done on the main thread, so there’s no concurrency to speak of).

    I might recommend trying to leverage some of the BitmapFactory.Options (Docs link) available to you when you decode the asset. In particular, you should be able to do all the scaling you need with a combination of the inScaled, inDensity, and inTargetDensity options. If you pass these to your decodeStream() method, you could likely remove all the subsequent code used to resize the image before returning.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to get Absolute path to Folder in Assets. Some like this for
I'm familiar with tools like Deadweight for finding CSS not in use in your
I need to use the assets library: i've found a snippets like this: [library
I am using AdoNetAppender (SQL server) in my asp.net application and would like use
I like to use static functions in C++ as a way to categorize them,
I like to use Emacs' shell mode, but it has a few deficiencies. One
I like to use IPython's zope profile to inspect my Plone instance, but a
Most websites use - (like Stack Overflow) but most PHP frameworks generate + encoded
I like to use markdown notation in my subversion commit messages, planning to one
I like to use MySQL to do quantitative analysis and statistics. I would like

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.