Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Xamarin Android-图像到文本_C#_Android_Xamarin - Fatal编程技术网

C# Xamarin Android-图像到文本

C# Xamarin Android-图像到文本,c#,android,xamarin,C#,Android,Xamarin,我发现了以下代码: // provide read access to the file FileStream fs = new FileStream(media.Path, FileMode.Open,FileAccess.Read); // Create a byte array of file stream length byte[] ImageData = new byte[fs.Length]; //Read block of bytes from stream into the by

我发现了以下代码:

// provide read access to the file
FileStream fs = new FileStream(media.Path, FileMode.Open,FileAccess.Read);
// Create a byte array of file stream length
byte[] ImageData = new byte[fs.Length];
//Read block of bytes from stream into the byte array
fs.Read(ImageData,0,System.Convert.ToInt32(fs.Length));
//Close the File Stream
fs.Close();
string _base64String = Convert.ToBase64String (ImageData);
我不确定如何传入图像,以及使用哪些导入使其工作。我基本上想拍摄一幅图像并将其转换为文本


谢谢

我建议将图像存储在blob文件中。 但是,如果您真的想将它们存储在字符串中,您可以通过以下代码片段来实现

到字符串

byte[] ImageData = File.ReadAllBytes(@"Path to the image to load");
        string _base64String = Convert.ToBase64String(ImageData);
到byteArray

byte[] data = Convert.FromBase64String(_base64String);
        File.WriteAllBytes(@"Path to the image to store", data);

我建议将图像存储在blob文件中。 但是,如果您真的想将它们存储在字符串中,您可以通过以下代码片段来实现

到字符串

byte[] ImageData = File.ReadAllBytes(@"Path to the image to load");
        string _base64String = Convert.ToBase64String(ImageData);
到byteArray

byte[] data = Convert.FromBase64String(_base64String);
        File.WriteAllBytes(@"Path to the image to store", data);


你说的“拍摄图像并将其转换为文本”是什么意思?这样做比这里要复杂得多。不,我需要将图像转换为文本,以便将其存储在数据库中。第一个参数media.Path是图像的文件路径。我如何将图像分配给值media?抱歉,我对xamarin和c#还是很陌生。如果你想将其存储在数据库中,为什么不将其存储为blob?什么是“拍摄图像并将其转换为文本?”你是指读取图像中的文本?这样做比这里要复杂得多。不,我需要将图像转换为文本,以便将其存储在数据库中。第一个参数media.Path是图像的文件路径。我如何将图像分配给值media?抱歉,我对xamarin和c#还是很陌生。如果你想将其存储在数据库中,为什么不将其存储为blob?太棒了,我如何引用图像(例如在DCIM中)?该路径看起来是什么样的?您可以使用System.Environment.GetFolderPath抱歉,再说一次。我如何使用它来获取特定目录?谢谢你的帮助。我有点像个傻瓜。有了Environment.GetFolderPath,你可以得到一个基本的folderAgain,我很可怜,它的文件路径会是什么样子?例如,在Windows中是C:\。。。在安卓系统中会是什么?你能给我一个示例片段吗。谢谢,虽然我快到了!太棒了,我该如何引用DCIM中的图像?该路径看起来是什么样的?您可以使用System.Environment.GetFolderPath抱歉,再说一次。我如何使用它来获取特定目录?谢谢你的帮助。我有点像个傻瓜。有了Environment.GetFolderPath,你可以得到一个基本的folderAgain,我很可怜,它的文件路径会是什么样子?例如,在Windows中是C:\。。。在安卓系统中会是什么?你能给我一个示例片段吗。谢谢,虽然我快到了!