Java 在android中本地存储图像的最佳方式是什么?
我想创建一个离线应用程序,用户可以在其中添加带有图像详细信息的图像。我想知道离线存储图像的最佳方式是什么Java 在android中本地存储图像的最佳方式是什么?,java,android,android-layout,android-fragments,Java,Android,Android Layout,Android Fragments,我想创建一个离线应用程序,用户可以在其中添加带有图像详细信息的图像。我想知道离线存储图像的最佳方式是什么 我应该使用SQLite blob格式、SQLite base64编码字符串,还是应该将其存储在内部存储器中,还是应该将其存储在共享首选项中。请帮助我,如果您知道其他方法,请提及。内部存储是最好的。 若您想保持它的私密性,请更改图像的格式,然后保存 否则按原样保存要在本地保存图像,请使用以下代码: private String saveToInternalStorage(Bitmap bitm
我应该使用SQLite blob格式、SQLite base64编码字符串,还是应该将其存储在内部存储器中,还是应该将其存储在共享首选项中。请帮助我,如果您知道其他方法,请提及。内部存储是最好的。 若您想保持它的私密性,请更改图像的格式,然后保存
否则按原样保存要在本地保存图像,请使用以下代码:
private String saveToInternalStorage(Bitmap bitmapImage){
ContextWrapper cw = new ContextWrapper(getApplicationContext());
// path to /data/data/yourapp/app_data/imageDir
File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
// Create imageDir
File mypath=new File(directory,"profile.jpg");
FileOutputStream fos = null;
try {
fos = new FileOutputStream(mypath);
// Use the compress method on the BitMap object to write image to the OutputStream
bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, fos);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return directory.getAbsolutePath();
}
“我应该使用SQLite blob格式、SQLite base64编码字符串还是应该将其存储在内部存储器中”
在大多数情况下,最后一个选项是最好的