我是android开发的新手。我的应用程序是关于拍照和粘贴一些贴纸。我使用了一些开源过滤器代码。但我的应用程序经常崩溃,导致以下错误:
8971-9026/co.wansi.yixia E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #3
Process: co.wansi.yixia, PID: 8971
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.OutOfMemoryError
at co.wansi.yixia.ImageFilter.GaussianBlurFilter.ApplyBlur(GaussianBlurFilter.java:61)
at co.wansi.yixia.ImageFilter.GaussianBlurFilter.process(GaussianBlurFilter.java:150)
at co.wansi.yixia.ImageFilter.SoftGlowFilter.process(SoftGlowFilter.java:45)
at co.wansi.yixia.yixia.act.picturedeal.view.PictureDetialFilterItemView$processImageTask.doInBackground(PictureDetialFilterItemView.java:108)
at co.wansi.yixia.yixia.act.picturedeal.view.PictureDetialFilterItemView$processImageTask.doInBackground(PictureDetialFilterItemView.java:87)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
我的代码是:
public class processImageTask extends AsyncTask<Void, Void, Bitmap> {
private IImageFilter filter;
private Activity activity = null;
public processImageTask(Activity activity, IImageFilter imageFilter) {
this.filter = imageFilter;
this.activity = activity;
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
}
public Bitmap doInBackground(Void... params) {
Image img = null;
try {
Bitmap bitmap = defaultBitmap;
img = new Image(bitmap);
if (filter != null) {
img = filter.process(img);
img.copyPixelsFromBuffer();
}
return img.getImage();
} catch (Exception e) {
if (img != null && img.destImage.isRecycled()) {
img.destImage.recycle();
img.destImage = null;
System.gc();
}
} finally {
if (img != null && img.image.isRecycled()) {
img.image.recycle();
img.image = null;
System.gc();
}
}
return null;
}
@Override
protected void onPostExecute(Bitmap result) {
if (result != null) {
super.onPostExecute(result);
mGPUImageView.setImageBitmap(result);
}
}
}
是out of memory
还是multiple thread
问题?