Android 图像未存储在内存中
我使用此代码将图像存储在内部存储器中,但图像并没有保存在内部存储器中,而是存储在外部存储器中,路径为:/storage/sdcard0/DCIM/CAMERA/IMG_2345.,jpgAndroid 图像未存储在内存中,android,Android,我使用此代码将图像存储在内部存储器中,但图像并没有保存在内部存储器中,而是存储在外部存储器中,路径为:/storage/sdcard0/DCIM/CAMERA/IMG_2345.,jpg private String saveToInternalMemory(Bitmap bitmap,String imgName){ ContextWrapper cw = new ContextWrapper(getApplicationContext()); File file = new
private String saveToInternalMemory(Bitmap bitmap,String imgName){
ContextWrapper cw = new ContextWrapper(getApplicationContext());
File file = new File(getCacheDir(),"imageDirectory");
//File directory = cw.getDir("imageDirectory", Context.MODE_PRIVATE);
//File userDirectory = new File(directory,imgName);
File myPath = new File(file,imgName);
Log.e("path",myPath.getAbsolutePath());
FileOutputStream fos = null;
try {
fos = new FileOutputStream(myPath);
bitmap.compress(Bitmap.CompressFormat.PNG,100,fos);
Log.e("img_name",bitmap.toString());
}catch (FileNotFoundException e){}
catch (IOException e){}finally {
try {
fos.close();
}catch (IOException e){}
}
return myPath.getAbsolutePath();
}
有人能解释一下错误是什么吗?“但图像未保存在内部存储器中”--请详细解释您是如何确定的。“而是使用path存储在外部存储器中”——这是一个不同的文件。例如,它是一个JPEG,而您的代码正在创建一个PNG。另外,在不记录异常的情况下,千万不要捕获异常,尤其是当抛出这些异常的代码出现问题时。@commonware我想将图像保存在手机内存中,而不是sd卡中,但它存储在sd卡中。这就是问题所在。。而且“imageDirectory”文件夹也没有创建……这并没有详细解释您如何确定“图像未保存在内部存储器中”。毕竟,你不能很容易地在设备上看到。我猜你找错地方了。但是,在您详细解释如何确定“图像未保存在内部存储器中”之前,没有人能帮您。@Commonware好的。您能告诉我“imageDirectory”文件夹的创建位置吗?我能在电话中找到此目录吗?请阅读。