Frazzle Frazzle - 1 year ago 196
Android Question

Xamarin Android - Image to Text

I have found this code:

// 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
//Close the File Stream
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.


Answer Source

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

To string

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

To byteArray

byte[] data = Convert.FromBase64String(_base64String);
        File.WriteAllBytes(@"Path to the image to store", data);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download