c# - Xamarin Forms 项目中的 Imread 方法找不到我的图像
问题描述
我正在尝试在我的应用程序上使用否定图像。该图像位于 android 项目的 drawable 文件夹中。
我试过只使用图像的名称,就像图像xaml一样:
<Image x:Name="img"
Source="thanos.jpg" />
C#:
Mat image = CvInvoke.Imread("thanos.jpg", ImreadModes.AnyColor);
但我得到了例外:System.ArgumentException : File thanos.jpg do not exist
我试过在路径中添加drawable、资源、/、\,但仍然是同样的错误。
有任何想法吗 ?
解决方案
此解决方案仅适用于 android atm。
首先,添加 android 路径private const string pathAndroid = "/storage/emulated/0/Android/data/com.companyname.**YourAppName**/files"
,因为 System.Environment.GetFolderPath(System.Environment.SpecialFolder.**WhateverYouChooseThere**)
链接到其他文件夹。
然后 Imread 确实需要文件,所以我直接在手机中添加了文件(我的应用程序已经包含图像),并将路径与文件名结合起来:
var pathfile = Path.Combine(pathAndroid + "/hello.JPG"); //whatever your file name
最终,我可以使用 Imread :
Mat img = CvInvoke.Imread(pathfile);
CvInvoke.CvtColor(img, img, ColorConversion.Rgb2Gray);
CvInvoke.Imwrite(pathAndroid + "/result.JPG", img); //save the image
推荐阅读
- python - Python 中的异常处理以实现持续执行
- 3d - 为 .dae 3d 模型添加纹理
- javascript - 调试通过 ngrok 运行的 JavaScript 代码
- swift - Swift Firebase Twitter 登录:无法获取凭据
- c++ - 什么是 .c.obj / .cpp.obj 文件?
- c# - GAC 之外的参考资料
- android - AndroidManifest.xml 不允许匹配“[xX][mM][lL]”的处理指令目标
- python - 如何在 python(pandas) 中获得文件编辑权限
- linux - UNIX/LINUX 递归计数
- c++ - 共享可执行文件时找不到库 gcc dll 错误