1

Hy everbody!

I've a minor problem but a problem!

I transmit between 2 activities 6 photos max. but the loading between 2 is really long (6-10sec).

my code :

String[] toShare = getIntent().getStringArrayExtra("toShare"); for (int i = 0; i < toShare.length; i++) { if(toShare[i] != null){ LesPlus.get(i).setImageBitmap(genereThumb(toShare[i])); }else{ LesPlus.get(i).setImageDrawable(getResources().getDrawable(R.drawable.btnadd)); } } 

genereThumb :

 File file = new File(path); FileInputStream fs=null; Bitmap bm = null; DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); int largeurEcran = dm.widthPixels; int LargeurCol = (int) ((largeurEcran / 3) - 15); BitmapFactory.Options bfOptions=new BitmapFactory.Options(); bfOptions.inDither=false; bfOptions.inPurgeable=true; bfOptions.inInputShareable=true; bfOptions.inTempStorage=new byte[32 * 1024]; try { fs = new FileInputStream(file); } catch (FileNotFoundException e) { System.out.println(e); } try { if(fs!=null) bm=BitmapFactory.decodeFileDescriptor(fs.getFD(), null, bfOptions); } catch (IOException e) { e.printStackTrace(); } finally{ if(fs!=null) { try { fs.close(); } catch (IOException e) { System.out.println(e); } } } return Bitmap.createScaledBitmap(bm, LargeurCol, LargeurCol, true); } 

I devellop on a Galaxy S2 if its can help :D. Thanks for your anwers

8
  • 1
    To manage bitMap it is adviced to use hard cache. Take a look at github.com/nostra13/Android-Universal-Image-Loader it is the best lib i've known so far to manage download, redim; cache and display images Commented Jul 18, 2013 at 12:20
  • thanks but i don't find anything about thumbnails :( and i would like to use the default android libraries Commented Jul 18, 2013 at 12:28
  • I've tried but it display nothing and .writeDebugLogs() doesn't work! it needs a cast :( Commented Jul 18, 2013 at 13:18
  • are you talking about universal image loader ? Commented Jul 18, 2013 at 13:26
  • And one point, your work on bitmap should not be on the main thread ;) Commented Jul 18, 2013 at 13:27

2 Answers 2

0

The link to AsyncTask documentation :

http://developer.android.com/reference/android/os/AsyncTask.html

Some tuto :

http://android-developers.blogspot.fr/2009/05/painless-threading.html

The link to threading documentation :

http://developer.android.com/guide/components/processes-and-threads.html

http://developer.android.com/guide/faq/commontasks.html#threading

Sign up to request clarification or add additional context in comments.

1 Comment

i will try in 30minutes
0

Thanks a lot! i've read then and if i understand,

if i use this :

public void onClick(View v) { new DownloadImageTask().execute("http://example.com/image.png"); 

}

private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> { /** The system calls this to perform work in a worker thread and * delivers it the parameters given to AsyncTask.execute() */ protected Bitmap doInBackground(String... urls) { return loadImageFromNetwork(urls[0]); } /** The system calls this to perform work in the UI thread and delivers * the result from doInBackground() */ protected void onPostExecute(Bitmap result) { mImageView.setImageBitmap(result); } 

}

my bitmap(s) will be load more fastly? if it's exactly that so powerfull

3 Comments

It wont be faster, it just wont block the UI. And if that's what you want to do Universalimageloader do that better (AND maybe faster)
so i replace new downloadImageTask... in the onclick by the UIL ?