android - 如何保存 Uri 表单图像?
问题描述
我想从保存在内部存储器中的图像中保存 Uri 或 pathc,以便在获取并放入 viewImage 表单毕加索之后,但这不起作用。
public File SaveImage(Bitmap ImageToSave) {
String file_path = Environment.getExternalStorageDirectory()
.getAbsolutePath() + NameOfFolder;
String CurrentDateAndTime = getCurrentDateAndTime();
File dir = new File(file_path);
if (!dir.exists()) {
dir.mkdirs();
}
File file = new File(dir, NameOfFile + CurrentDateAndTime + ".jpg");
try {
FileOutputStream fOut = new FileOutputStream(file);
ImageToSave.compress(Bitmap.CompressFormat.JPEG, 85, fOut);
fOut.flush();
fOut.close();
MakeSureFileWasCreatedThenMakeAvabile(file);
AbleToSave();
}
catch(FileNotFoundException e) {
UnableToSave();
}
catch(IOException e) {
UnableToSave();
}
//return file.getPath();
//return file.getAbsolutePath();
return file;
}
我保存图像。
File file = saveImage(currentBitmap);
Picasso.get().load(file.getAbsolutePath()).into(imageView);
但永远不要加载图像
注意:currentBitmap 不能使用(因为它是为了保存在 Realm 数据库中,占用空间很大)。
谢谢你的支持。
解决方案
推荐阅读
- python - 动态更新 QLineSeries 的问题
- vue.js - 如何将Paypal智能按钮集成到vue浏览器扩展pwa中
- python - 根据里面的比赛删除字符串
- android - Google Play Console 新应用签名流程:我们每次发布应用时都需要 .pepk 和 .keystore 文件吗?
- prisma - 无法解决 Prisma 1 - 1 和 1 - n 关系错误
- c# - 使用 EF Core 在 SQL Server 中处理乐观并发 - 更新子级时,如何更新父级?
- sql - SQL- 查询无效,因为聚合函数对每个日期和 ID 进行简单计算
- ruby-on-rails - Ruby on Rails:如何使用 JSONPath 访问(并保存到数据库)JSON 数组中的嵌套对象/属性?
- audio - MIT Scratch 中两个精灵之间的声音交互
- reactjs - React TypeError:this.props.message.map 不是函数