我认为这应该很简单,但我无法弄清楚。
我不断收到错误消息:System.IO.DirectoryNotFoundException: Could not find a part of the path "/storage/emulated/0/Pictures/Screenshots/name.jpg"
。
代码:
string root = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryPictures).Path;
File myDir = new File(root + "/Screenshots");
myDir.Mkdirs();
string timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").Format(new Date());
string fname = CommunicationHandler.GetNickname() + "|" + timeStamp + ".jpg";
File file = new File(myDir, fname);
if (file.Exists())
file.Delete();
try
{
using (System.IO.Stream outStream = System.IO.File.Create(file.Path))
{
finalBitmap.Compress(Bitmap.CompressFormat.Jpeg, 100, outStream);
outStream.Flush();
outStream.Close();
}
}
catch (Exception e)
{
Toast.MakeText(Activity, e.ToString(), ToastLength.Long).Show();
}
此外,我无法手动访问/ storage / emulated / 0。
有人有主意吗?
编辑!!:我必须手动进入应用程序设置并授予权限,现在没有崩溃,并且似乎可以正常工作,但是我在图库中找不到该图像。
所以现在的问题是..我应该如何启动扫描,以便图像出现在图库中?
答案 0 :(得分:1)
如果要创建新目录,可以使用System.IO.Directory.CreateDirectory(root);
来创建它。
//create a directory called MyCamera
string root = Environment.GetExternalStoragePublicDirectory(Environment.DirectoryDcim).ToString() + "/MyCamera/";
//create the Directory
System.IO.Directory.CreateDirectory(root);
答案 1 :(得分:0)