在Android中跨进程传递大图片是一项具有挑战性的任务,因为Binder传输数据的限制。为了安全有效地传递大图片,你可以使用以下方法:
方法一:通过文件共享
- 将图片保存到共享存储:将图片保存到应用的共享存储或外部存储中,例如
getExternalFilesDir()。 - 传递文件路径:在两个进程之间通过Intent或AIDL传递文件路径。
- 读取图片:目标进程从共享存储中读取图片。
代码示例:
发送进程:
File imageFile = new File(getExternalFilesDir(null), "shared_image.jpg");
// 将图片保存到imageFile
Intent intent = new Intent(this, TargetService.class);
intent.putExtra("image_path", imageFile.getAbsolutePath());
startService(intent

最低0.47元/天 解锁文章
2757

被折叠的 条评论
为什么被折叠?



