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 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
I have this method in my db class public function query($queryString) { if (!$this->_connected)
I have this method: public bool CanExecute() And after 70 commits, I added an
I have this method: private delegate void watcherReader(StreamReader sr); private void watchProc(StreamReader sr) {
We've created a generic method like so: public TReturnType GetValue(string key) { var configurationParameter
I use this method for inserting a textbox in a tablecell protected void EditAttivitaClick(object
I have this method on a webpart: private IFilterData _filterData = null; [ConnectionConsumer(Filter Data
Every time I call this method my NSMutableData is leaking and I cannot figure
Having recently discovered this method of development, I'm finding it a rather nice methodology.
Should I be using this method of throwing errors: if (isset($this->dbfields[$var])) { return $this->dbfields[$var];

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.