[英]Save a bitmap in internal cache folder
I need to do several SIMPLE things... but I can't get it right我需要做几件简单的事情……但我做对了
I tried this kind of approach :我尝试过这种方法:
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();
}
}
It saves the file but I don't know where ?它保存文件,但我不知道在哪里?
With getExternalCacheDir() I can see the file on the device but not with openFileOutput.使用 getExternalCacheDir() 我可以看到设备上的文件,但不能使用 openFileOutput。
I can load the bitmap with :我可以加载位图:
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;
}
But again just using the name但再次只是使用名称
It saves the file but I don't know where ?
它保存文件,但我不知道在哪里?
It saves it in internal storage .它将它保存在内部存储器中。
I can load the bitmap with
我可以加载位图
Then your code would seem to be working just fine.那么你的代码似乎工作得很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.