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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:05:06+00:00 2026-05-25T02:05:06+00:00

This is a method i created to put Bitmap into cache.. //Caching method to

  • 0

This is a method i created to put Bitmap into cache..

        //Caching method to cache images loaded from the URL's.
    public void putBitmapInDiskCache(URI imageUri, Bitmap avatar) {   
            File cacheDir = new File(MainMenu.this.getCacheDir(), "thumbnails");
            cacheDir.mkdirs();
            File cacheFile = new File(cacheDir, ""+imageUri.hashCode());   
            try {      
            cacheFile.createNewFile();       
            FileOutputStream fos = new FileOutputStream(cacheFile);    
            avatar.compress(CompressFormat.PNG, 100, fos);   


            fos.flush();       
            fos.close();    
            } catch (Exception e) {       
            Log.e("error", "Error when saving image to cache. ", e);    

            }   



            }

The only problem is i set the Bitmap width and height parameter initially when it is downloaded. But when it is put into cache and pulled out, it loses its width and height and becomes to big. When it is scrolled off the screen it is set correctly again. intially it loses its width and height.

EDIT: I load the bitmap with my getimagefromCache() method.

public void getImagesfromCache() throws MalformedURLException{
if(new File(new File(this.getApplicationContext().getCacheDir(), "thumbnails"),"" + imageCacheUri.hashCode()).exists()){
String cacheFile = this.getApplicationContext().getCacheDir() +"/thumbnails/"+ imageCacheUri.hashCode();
            ImageView i = new ImageView(this.getApplicationContext());
            FileInputStream fis = null;
            try {
                fis = new FileInputStream(cacheFile);
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            Bitmap bm = BitmapFactory.decodeStream(fis);

             i.setImageBitmap(bm);
             i.setTag(mImageURLs);
             putBitmapInDiskCache(imageCacheUri, bm);



        //Set the BaseAdapter to a gallery, holding the images  
             ((Gallery) findViewById(R.id.gallery))
              .setAdapter(new ImageAdapter(MainMenu.this));
  • 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-25T02:05:07+00:00Added an answer on May 25, 2026 at 2:05 am

    There is an Matrix parameter on the createBitmap method that will allow you to resize your Bitmap and so you can store it with the resolution you want. See how here (it’s an excellent tutorial, by the way).

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

Sidebar

Related Questions

I have a simple method which is called from multiple threads; @Override public Bitmap
Hi I have created this method to do the folowing: -it takes a bitmap
I'd like to use this method to create user-friendly URL. Because my site is
With this method declaration (no overloads): void Method(double d) { // do something with
Can this method work? public String sayHello(){ return Hello.jsp?name= + laala; } I am
I use this method for inserting a textbox in a tablecell protected void EditAttivitaClick(object
I have the following method: public IEnumerable<Foo> GetFoo(int x, string y) { return from
I'm creating new Site Definitions using this method: http://weblogs.asp.net/paulballard/archive/2007/04/09/creating-a-custom-sharepoint-2007-portal-site-definition-using-the-portalprovisioningprovider-class.aspx and when they get created,
This method works as expected - it creates a JTree with a root node
This is a design question: when do I need to create/use a static method

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.