通过图片地址获取图片的base64,再通过base64获取二进制数据

class Program
{
    static void Main(string[] args)
    {

        string base64 = getFileBase64("D:\\Users\\VatInvoiceOCR1.jpg");

        byte[] file = Convert.FromBase64String(base64);

        Console.WriteLine($"图片的base64编码:{base64}");
        Console.WriteLine($"图片的二进制数据:{file}");
        Console.ReadKey();
    }
    public static string getFileBase64(String fileName)
    {
          FileStream filestream = new FileStream(fileName, FileMode.Open);
          byte[] arr = new byte[filestream.Length];
          filestream.Read(arr, 0, (int)filestream.Length);
          string baser64 = Convert.ToBase64String(arr);
          filestream.Close();
          return baser64;
    }
}
posted @ 2022-03-15 09:40  悟自省  阅读(400)  评论(0编辑  收藏  举报