0

I've found this sample code to convert an image to base 64, I'm not sure how to pass an image into it though. I want to be able to give a path to a specific directory. I've managed to find a file with this code:

byte[] ImageData = File.ReadAllBytes("storage/emulated/0/DCIM/Camera/img.jpg"); 

But I need to pass that into the following code.

public string ImageToBase64(Image image, System.Drawing.Imaging.ImageFormat format) { using (MemoryStream ms = new MemoryStream()) { // Convert Image to byte[] image.Save(ms, format); byte[] imageBytes = ms.ToArray(); // Convert byte[] to Base64 String string base64String = Convert.ToBase64String(imageBytes); return base64String; } } 

Hope you can help. Thanks.

3

1 Answer 1

2
byte[] ImageData = File.ReadAllBytes(path_to_file); string base64String = Convert.ToBase64String(ImageData); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.