c# - Xamarin 找不到路径的一部分
问题描述
我正在尝试将位图保存到 Android 存储。我的代码如下所示:
var folderPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
var filePath = System.IO.Path.Combine(folderPath, "Pictures/profile_picture.png");
var stream = new FileStream(filePath, FileMode.Create);
bitmap.Compress(Bitmap.CompressFormat.Png, 100, stream);
stream.Close();
但是应用程序进入中断模式并显示:
System.IO.DirectoryNotFoundException:找不到路径的一部分。
任何帮助表示赞赏。在此先感谢,佐丁格尔。
解决方案
“图片”目录未创建。因此,您收到“找不到路径的一部分”错误。如下更改代码,或者您可以为“图片”创建目录,然后使用相同的代码应该可以工作。
var filePath = System.IO.Path.Combine(folderPath, "profile_picture.png");
创建目录的代码
Directory.CreateDirectory(System.IO.Path.Combine(folderPath, "Pictures"));
推荐阅读
- emacs - 使用预定义的参数运行 magit-log
- google-app-engine - GCP - Google App Engine - 如何删除自定义域?
- python - 在 IIS 上运行 python websockets 应用程序
- android - 错误:找不到字段的设置器 - 房间
- mysql - MYSQL - 更新时截断列 X 的数据,但插入时不截断
- ruby-on-rails - 如何查找/检索已在 Rails 中配置的 Rack::Timeout 超时值?
- php - PHP GD 库中的 Bangla Unicode 字体中断
- r - 如何更正 R 中的 rcorr() 警告
- c# - 在 C# Windows 服务中使用异步事件处理程序
- c# - IOS 13 和 OSX 10.15 (.NET) 上的 Safari 中的 SAML 请求不安全