Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to scale Bitmap put, and loaded from cache initially?
    primarykey
    data
    text
    <p>This is a method i created to put Bitmap into cache..</p> <pre><code> //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); } } </code></pre> <p>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.</p> <p>EDIT: I load the bitmap with my getimagefromCache() method.</p> <pre><code>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)); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload