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

  • 1
    To manage bitMap it is adviced to use hard cache. Take a look at https://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 – An-droid Jul 18 '13 at 12:20
  • thanks but i don't find anything about thumbnails :( and i would like to use the default android libraries –  Jul 18 '13 at 12:28
  • I've tried but it display nothing and .writeDebugLogs() doesn't work! it needs a cast :( –  Jul 18 '13 at 13:18
  • are you talking about universal image loader ? – An-droid Jul 18 '13 at 13:26
  • And one point, your work on bitmap should not be on the main thread ;) – An-droid Jul 18 '13 at 13:27
  • yes i speak about UIL, so i have to work on bitmap in another thread in the activity? sorry but i begin in android dev –  Jul 19 '13 at 07:33
  • To do long operations you can use AsyncTask, else there is Thread and handler. As long as you do the work in another thread the IHM won't be affected or blocked – An-droid Jul 19 '13 at 07:39
  • @MaximeVince save image in SD card get the thumbnail and delete after you want . http://stackoverflow.com/a/7529603/501483 – dharmendra Jul 19 '13 at 07:56

2 Answers2

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

  • 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) – An-droid Jul 19 '13 at 08:36
  • so i replace new downloadImageTask... in the onclick by the UIL ? –  Jul 19 '13 at 08:54
  • Some link to see how UIL works - http://stackoverflow.com/questions/15627031/how-to-use-android-universal-image-loader - http://stackoverflow.com/questions/15041891/android-universal-image-loader-autoresize - http://stackoverflow.com/questions/13854125/how-to-use-universal-image-loader - http://stackoverflow.com/questions/10257667/android-how-to-intantiate-universal-image-loader – An-droid Jul 19 '13 at 08:59