在内部缓存文件夹中保存位图
Save a bitmap in internal cache folder
我需要做几件简单的事情...但我做不对
- 将位图保存到内部缓存以备后用,现在我保存名称(例如:name_2347458.jpg)
我试过这种方法:
public static void saveFile(Context context, Bitmap bitmap, String picName) {
FileOutputStream fileOutputStream;
try {
fileOutputStream = context.openFileOutput(picName, Context.MODE_PRIVATE);
bitmap.compress(Bitmap.CompressFormat.JPEG, 30, fileOutputStream);
fileOutputStream.close();
} catch (FileNotFoundException e) {
Log.d(TAG, "file not found");
e.printStackTrace();
} catch (IOException e) {
Log.d(TAG, "io exception");
e.printStackTrace();
}
}
它保存了文件,但我不知道保存在哪里?
使用 getExternalCacheDir() 我可以看到设备上的文件,但不能使用 openFileOutput。
我可以加载位图:
public static Bitmap loadBitmap(Context context, String picName) {
Bitmap bitmap = null;
FileInputStream fileInputStream;
try {
fileInputStream = context.openFileInput(picName);
bitmap = BitmapFactory.decodeStream(fileInputStream);
fileInputStream.close();
} catch (FileNotFoundException e) {
Log.d(TAG, "file not found");
e.printStackTrace();
} catch (IOException e) {
Log.d(TAG, "io exception");
e.printStackTrace();
}
return bitmap;
}
但还是只用名字
It saves the file but I don't know where ?
保存在internal storage.
I can load the bitmap with
那么您的代码似乎工作正常。
我需要做几件简单的事情...但我做不对
- 将位图保存到内部缓存以备后用,现在我保存名称(例如:name_2347458.jpg)
我试过这种方法:
public static void saveFile(Context context, Bitmap bitmap, String picName) {
FileOutputStream fileOutputStream;
try {
fileOutputStream = context.openFileOutput(picName, Context.MODE_PRIVATE);
bitmap.compress(Bitmap.CompressFormat.JPEG, 30, fileOutputStream);
fileOutputStream.close();
} catch (FileNotFoundException e) {
Log.d(TAG, "file not found");
e.printStackTrace();
} catch (IOException e) {
Log.d(TAG, "io exception");
e.printStackTrace();
}
}
它保存了文件,但我不知道保存在哪里?
使用 getExternalCacheDir() 我可以看到设备上的文件,但不能使用 openFileOutput。
我可以加载位图:
public static Bitmap loadBitmap(Context context, String picName) {
Bitmap bitmap = null;
FileInputStream fileInputStream;
try {
fileInputStream = context.openFileInput(picName);
bitmap = BitmapFactory.decodeStream(fileInputStream);
fileInputStream.close();
} catch (FileNotFoundException e) {
Log.d(TAG, "file not found");
e.printStackTrace();
} catch (IOException e) {
Log.d(TAG, "io exception");
e.printStackTrace();
}
return bitmap;
}
但还是只用名字
It saves the file but I don't know where ?
保存在internal storage.
I can load the bitmap with
那么您的代码似乎工作正常。