来自于:Rex_IT

    1. #region 图片的Base64
    2. /// <summary>
    3. /// 图片的Base64转换
    4. /// </summary>
    5. public class ImageBase64
    6. {
    7. /// <summary>
    8. /// 将图片数据转换为Base64字符串
    9. /// </summary>
    10. /// <param name="imagefilepath">文件路径</param>
    11. public static String ImageToBase64(String imagefilepath)
    12. {
    13. byte[] bytes = FileUtil.getBytes(imagefilepath);
    14. string base64 = Convert.ToBase64String(bytes);
    15. return base64;
    16. }
    17. /// <summary>
    18. /// 将Base64字符串转换为图片
    19. /// </summary>
    20. /// <param name="Strbase64">图片的Base64值</param>
    21. public static Image Base64ToImage(string Strbase64)
    22. {
    23. byte[] bytes = Convert.FromBase64String(Strbase64);
    24. System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes);
    25. System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
    26. return img;
    27. }
    28. }
    29. #endregion