C# 图片转为Base64

/// 
/// 图片转Base64
/// 
/// 图片的完整路径
/// 
public static string ImgToBase64(string ImageFileName)
{
    try
    {
        Bitmap bmp = new Bitmap(ImageFileName);

        MemoryStream ms = new MemoryStream();
        bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
        byte[] arr = new byte[ms.Length];
        ms.Position = 0;
        ms.Read(arr, 0, (int)ms.Length);
        ms.Close();
        return Convert.ToBase64String(arr);
    }
    catch (Exception)
    {
        return null;
    }
}

你可能感兴趣的:(C# 图片转为Base64)