Xamarin Android - 图像到文本 [英] Xamarin Android - Image to Text

查看:16
本文介绍了Xamarin Android - 图像到文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了这个代码:

// 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);

我不确定如何传入图像以及使用哪些导入来使其工作.我基本上想拍摄一张图片并将其转换为文本.

I'm not sure how to pass in an image and which imports to use to get it working. I basically want to take an image and convert it to text.

谢谢

推荐答案

我建议将图像存储在 blob 文件中.但是如果你真的想将它们存储在一个字符串中,你可以使用以下代码片段来实现它

I recommend storing images in a blob file. But if you really want to store them in a string you can achieve it with the following code snippets

到字符串

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);

这篇关于Xamarin Android - 图像到文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆