0
我目前將從互聯網上下載的圖像保存到磁盤。我希望能夠在用戶關閉應用程序時刪除圖像。我想將所有圖像保存在一個文件夾中,以便刪除它們。我做了getActivity().getCacheDir().getAbsolutePath()+ File.separator + "newfoldername"
以獲取文件夾的路徑。不知道如何將圖像添加到文件夾中。從文件夾中刪除緩存的圖像
public void saveImage(Context context, Bitmap b, String name_file, String path) {
FileOutputStream out;
try {
out = context.openFileOutput(name_file, Context.MODE_PRIVATE);
b.compress(Bitmap.CompressFormat.JPEG,90, out);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public Bitmap getImageBitmap(Context context, String name) {
try {
FileInputStream fis = context.openFileInput(name);
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 1;
Bitmap b = BitmapFactory.decodeStream(fis,null, options);
b.getAllocationByteCount());
fis.close();
return b;
} catch (Exception e) {}
return null;
}
@android戰士 - 我如何閱讀這些圖像?以及如何在應用程序關閉時刪除該文件夾。 – user3757801
@ user3757801閱讀圖片是什麼意思? – CodeWarrior
@ AndroidWarrior-像從保存的圖像獲取位圖,所以我可以顯示它 – user3757801