0

此代码崩溃。为什么?

@Override
    protected String doInBackground(String... params) {

        try {
            image_compress = image_compress(changed_image);

            array_image.add(Effects_change.doColorFilter((image_compress), 0,
                    1, 0));
            array_image.add(Effects_change.doColorFilter((image_compress), 0,
                    0, 1));


            array_image.add(Effects_change.doColorFilter((image_compress), 0,
                    1.2, 1.8));

            array_image.add(Effects_change.doGreyscale(image_compress));
            array_image.add(Effects_change.doGamma((image_compress), 0.8, 0.8,
                    0.8));
            array_image.add(Effects_change.doGamma((image_compress), 1.8, 1.8,
                    1.8));
            array_image.add(Effects_change.doColorFilter((image_compress), 1.0,
                    0, 0));

            array_image.add(Effects_change.doColorFilter((image_compress), 0.5,
                    0.5, 0.5));
            array_image.add(Effects_change.doColorFilter((image_compress), 1.5,
                    1.5, 1.5));


            array_image.add(Effects_change.createSepiaToningEffect(
                    (image_compress), 100, 1.5, 0.6, 0.12));
            array_image.add(Effects_change.createSepiaToningEffect(
                    (image_compress), 100, 0.88, 1.45, 1.43));

            array_image.add(Effects_change.createSepiaToningEffect(
                    (image_compress), 100, 1.2, 0.87, 1.8));
            array_image.add(Effects_change.decreaseColorDepth((image_compress),
                    32));

            array_image.add(Effects_change.decreaseColorDepth((image_compress),
                    120));

            array_image.add(Effects_change.applyReflection(image_compress));
            //array_image.add(Effects_change.applynewReflection(image_compress));
            array_image.add(Effects_change.applyFleaEffect(image_compress));

            array_image.add(Effects_change.sharpen((image_compress), 15));



            array_image.add(Effects_change.createSepiaToningEffect(
                    (image_compress), 200, 0.50, 0.6, 0.20));
            array_image.add(Effects_change.createSepiaToningEffect(
                    (image_compress), 150, 1.2, 0.97, 2.1));

            array_image.add(Effects_change.applyGaussianBlur(image_compress));
            array_image.add(Effects_change.applyBlackFilter(image_compress));
            array_image.add(Effects_change.applyMeanRemoval(image_compress));

            array_image.add(Effects_change.applySnowEffect(image_compress));

            array_image.add(Effects_change.smooth((image_compress), 8));
            array_image.add(Effects_change.CharcoalEffect(image_compress));

            array_image.add(Effects_change.tintImage((image_compress), 80));
            array_image.add(Effects_change.roundCorner((image_compress), 45));

            array_image.add(Effects_change.boost((image_compress), 1,
                    (float) 1.5));
            array_image.add(Effects_change.boost((image_compress), 2,
                    (float) 0.30));
            array_image.add(Effects_change.boost((image_compress), 3,
                    (float) 0.67));
            array_image.add(Effects_change.emboss(image_compress));

            array_image.add(Effects_change.boost((image_compress), 1,
                    (float) .50));

            array_image.add(Effects_change.boost((image_compress), 2,
                    (float) 0.10));
            array_image.add(Effects_change.boost((image_compress), 3,
                    (float) 1.5));
            array_image.add(Effects_change.engrave(image_compress));
            array_image.add(Effects_change.applyHueFilter((image_compress), 3));

            array_image.add(Effects_change
                    .changeToNegativeEffect(image_compress));
            array_image.add(Effects_change.SketchImage(image_compress));

            array_image.add(Effects_change.doColorFilter(image_compress, 1.8, 1.2, 1));


            array_image.add(Effects_change.tintImage((image_compress), 180));

            array_image.add(Effects_change.applySaturationFilter(image_compress, 2));

            array_image.add(Effects_change.createContrast(image_compress, 100));

            array_image.add(Effects_change.applySaturationFilter((image_compress), 90));
            // array_image.add(Effects_change.posterize(image_compress, 10));

            // setProgress(""+(int)((total*100)/lenghtOfFile));

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        //array_image.add(Effects_change.setSepiaColorFilter(image_compress));

        return null;
    }

    @Override
    public void onPostExecute(String result) {
        super.onPostExecute(result);

        g.setAdapter(new ImageAdapter(Image_add_effects.this));
        g.setOnItemSelectedListener(Image_add_effects.this);

        try {
            pb.dismiss();
            pb=null;
        } catch (Exception e) {
            // TODO: handle exception
        }
    }

}

这是日志

04-07 22:36:08.450: W/dalvikvm(18429): threadid=13: thread exiting with uncaught exception(group=0x41fe82a0)
04-07 22:36:08.450: E/AndroidRuntime(18429): FATAL EXCEPTION: AsyncTask #2
04-07 22:36:08.450: E/AndroidRuntime(18429): java.lang.RuntimeException: An error occured while executing doInBackground()
04-07 22:36:08.450: E/AndroidRuntime(18429):    at android.os.AsyncTask$3.done(AsyncTask.java:299)
04-07 22:36:08.450: E/AndroidRuntime(18429):    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
04-07 22:36:08.450: E/AndroidRuntime(18429):    at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
04-07 22:36:08.450: E/AndroidRuntime(18429):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
04-07 22:36:08.450: E/AndroidRuntime(18429):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
04-07 22:36:08.450: E/AndroidRuntime(18429):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
04-07 22:36:08.450: E/AndroidRuntime(18429):    at java.lang.Thread.run(Thread.java:856)
04-07 22:36:08.450: E/AndroidRuntime(18429): Caused by: java.lang.OutOfMemoryError

我该如何解决这个问题?

4

1 回答 1

0

原因是java.lang.OutOfMemoryError您的计算占用了太多 RAM。

但是,如果不知道您在做什么,就很难说出究竟是什么导致了错误。可能您创建了太多图像/位图。

以下是有关您的应用程序可用多少 RAM 的信息:https ://stackoverflow.com/a/9940415/247013

调查思路:

  • 使用Bitmap.recycle()- 每当您不需要处理过的位图时调用它
  • 尽量不要将图像存储在 RAM 中,而是将它们保存到文件中
  • 看起来您正在尝试预先为任何可能的效果预先创建图像 - 考虑重新架构 - 仅在用户明确要求时才执行一种效果(按需)。
于 2013-04-07T20:06:30.540 回答