android - 选择图像相机/画廊时出现内存不足异常
问题描述
我正在使用下面的代码通过相机/画廊挑选图像,并将它们的路径保存在 Sq Lite 中,这很好。一切正常。
我的问题是在选择图像 40 或更高版本后,出现内存不足异常。
有人可以帮忙吗?
从相机中选择图像:
try {
String folder_main = "FOSImages";
File f = new File(Environment.getExternalStorageDirectory(), folder_main);
if (!f.exists()) {
f.mkdirs();
}
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File f1 = new File(android.os.Environment.getExternalStorageDirectory(),
"/" + folder_main + "/" + System.currentTimeMillis() + "_temp.jpg");
fileName = System.currentTimeMillis() + "_temp.jpg";
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f1));
startActivityForResult(intent, Constants.CAMERA_REQUEST_CODE);
} catch (Throwable throwable) {
throwable.printStackTrace();
}
onCaptureImageResult:
try {
File f = new File(Environment.getExternalStorageDirectory() + "/" + "FOSImages");
for (File temp : f.listFiles()) {
if (temp.getName().equals(fileName)) {
f = temp;
origionalPaths.add(f);
if (imageType == 1) {
stickerBeforeFileList.add(f);
horizentalAdapter1.notifyDataSetChanged();
} else {
stickerAfterFileList.add(f);
horizentalAdapter2.notifyDataSetChanged();
}
}
}
} catch (Throwable throwable) {
throwable.printStackTrace();
}
从图书馆挑选:
try {
Intent intent = new Intent(
Intent.ACTION_PICK,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
startActivityForResult(
Intent.createChooser(intent, "Select File"),
Constants.GALLARY_REQUEST_CODE);
} catch (Throwable throwable) {
throwable.printStackTrace();
}
onSelectFromGalleryResult:
try {
Uri selectedImageUri = data.getData();
File shopImageFile1 = new
File(Utilities.getRealPathFromURI(selectedImageUri, UberFormActivity.this));
if (imageType == 1) {
stickerBeforeFileList.add(carImageFile1);
horizentalAdapter1.notifyDataSetChanged();
} else {
stickerAfterFileList.add(carImageFile2);
horizentalAdapter2.notifyDataSetChanged();
}
} catch (Throwable throwable) {
throwable.printStackTrace();
}
解决方案
推荐阅读
- flutter - 调用公共 API 时,“String”类型不是“index”类型“int”的子类型
- java - 使用 Java 的 DoNotForward Graph Api 事件
- wordpress - 基于首次打开的浏览器重定向
- solidity - Solidity 结构体
- batch-file - 批处理文件 - 为什么在 Foreach 中设置变量会中断循环?
- python - 如何编写打印出从 1 到输入数字的所有正整数值并且每对数字翻转的程序?
- c - Glade2.2“lang C”按钮点击后隐藏窗口
- azure - 无法通过 azure-sdk-for-go 从 azure ad 获取应用程序域
- typo3 - TYPO3 自定义扩展的新标签
- python - 使用 Alpha Vantage 绘制 1 分钟数据