Hy everbody!
我有一个小问题但是有问题!
我在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));
}
}
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);
}
如果它可以提供帮助,我会对Galaxy S2进行开发:D。谢谢你的答案
答案 0 :(得分:0)
AsyncTask文档的链接:
http://developer.android.com/reference/android/os/AsyncTask.html
有些tuto:
http://android-developers.blogspot.fr/2009/05/painless-threading.html
线程文档的链接:
http://developer.android.com/guide/components/processes-and-threads.html
http://developer.android.com/guide/faq/commontasks.html#threading
答案 1 :(得分: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);
}
}
我的位图加载速度会更快?如果它真的那么强大