gpt4 book ai didi

android - 位图压缩和异步任务保存期间的问题

转载 作者:行者123 更新时间:2023-11-29 17:55:46 25 4
gpt4 key购买 nike

我正在编写一个带有自定义相机功能的应用程序。在捕获后的自定义相机中,我将捕获的图像绘制到 Canvas 上,并在捕获的图像上提供免费手绘,然后保存选项。在保存时,我将其保存为两张图像,这意味着一张包含手绘图,另一张不包含绘图。保存是通过写入输出流和压缩位图来完成的。位图的保存和压缩在两个独立的异步任务中完成。问题是我最多可以捕获图像 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 英寸平板电脑上进行测试。请给我解决方案。提前致谢。

最佳答案

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

关于android - 位图压缩和异步任务保存期间的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19547964/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com