【发布时间】:2019-04-22 23:59:29
【问题描述】:
我认为这应该很简单,但我无法弄清楚。
我不断收到错误消息: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..
为什么我无法将位图保存到我的手机图库中?上面的代码有什么问题?
【问题讨论】:
-
Android 有用于将图像保存到图库的 API。您不能只写入文件系统来执行此操作。见stackoverflow.com/questions/31296280/…
标签: c# xamarin bitmap stream android-external-storage