1

大家好!

我有一个小问题,但有问题!

我在 2 个活动之间传输最多 6 张照片。但是 2 之间的加载真的很长(6-10 秒)。

我的代码:

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));
        }
    }

通用拇指:

    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);
}

如果有帮助,我会开发 Galaxy S2 :D。谢谢你的回答

4

2 回答 2

0

非常感谢!我当时读过,如果我明白了,

如果我使用这个:

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);
}

}

我的位图会加载得更快吗?如果它真的那么强大

于 2013-07-19T08:04:51.540 回答