1

我正在编写一个带有自定义相机功能的应用程序。在捕获后的自定义相机中,我将捕获的图像绘制到画布上,并在捕获的 imgae 上提供免费手绘,然后保存选项。在保存时,我将其保存为两个图像,这意味着一个包含手绘图和另一个不包含绘图。保存是通过写入输出流和压缩位图来完成的。位图的保存和压缩在两个单独的异步任务中完成。问题是我最多可以捕获 16 或 17 次图像,但是在捕获和编辑之后按保存按钮,我得到异常“vm aborting Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1)”。异步任务一

public class SaveOriginalImage extends AsyncTask<String, Void, String> {
    OutputStream dataOutputStream;
    Bitmap bitMapOriginalImage;
    String fileName;
    Activity activityContext;
    ProgressDialog progressDialog;
    String sbCaption;
    String fileType;

    public SaveOriginalImage(Bitmap bitMap, String filePath,
            Activity currentActivity, String fileCaption) {
        this.bitMapOriginalImage = bitMap;
        this.fileName = filePath;
        this.activityContext = currentActivity;
        this.sbCaption = fileCaption;
    }

    @Override
    protected String doInBackground(String... params) {
        try {
            dataOutputStream = new FileOutputStream(fileName);

            bitMapOriginalImage
                    .compress(CompressFormat.PNG, 100, dataOutputStream);
            Collection.lastImageFilePath = fileName;

            dataOutputStream.flush();
            dataOutputStream.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    protected void onPreExecute() {

        super.onPreExecute();

    }

    @Override
    protected void onPostExecute(String result) {
        if (bitMapOriginalImage != null) {
            bitMapOriginalImage.recycle();
            bitMapOriginalImage = null;
        }
    }
}

异步任务 2

public class SaveFreeHandImage extends AsyncTask<String, Void, String> {
OutputStream dataOutputStream;
Bitmap bitMapToSave;
String fileName;
Activity activityContext;
ProgressDialog progressDialog;
String sbCaption;
String className;
String fileType;

public SaveFreeHandImage(Bitmap bitMap, String filePath,
        Activity currentActivity, String fileCaption, String className) {
    this.bitMapToSave = bitMap;
    this.fileName = filePath;
    this.activityContext = currentActivity;
    this.sbCaption = fileCaption;
    this.className = className;
}

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

        dataOutputStream = new FileOutputStream(fileName);

        bitMapToSave.compress(CompressFormat.PNG, 100, dataOutputStream);
        Collection.lastImageFilePath = fileName;
        try {
            dataOutputStream.flush();
            dataOutputStream.close();

            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    return null;
}

@Override
protected void onPostExecute(String result) {
    // super.onPostExecute(result);
    progressDialog.dismiss();

    HomeFinal.showCustomToast("Drawing saved to SD card ", 0, 0,
            activityContext);
    Collection.isNewImageAdded = false;
    DrawingView.colorD = Color.parseColor("#000000");
    if (DrawingView.paths != null) {
        if (DrawingView.paths.size() >= 1) {
            DrawingView.paths.clear();
        }
    }

    if (bitMapToSave != null) {
        if (!bitMapToSave.isRecycled()) {
            bitMapToSave.recycle();
            bitMapToSave = null;
        }
    }
}

@Override
protected void onPreExecute() {
    super.onPreExecute();
    progressDialog = ProgressDialog.show(activityContext, "", "Saving..");
    }
 }

我正在 lenovo a-300h 7 英寸平板电脑上进行测试。请给我解决方案。提前致谢。

4

1 回答 1

3

我自己解决了。这是因为过度使用位图,在处理位图后它工作得很好。

于 2013-10-27T06:34:58.643 回答