You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
882 B

1 month ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Drawing;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace ShenTun.IcCard.Common
  9. {
  10. public class ImageHelper
  11. {
  12. public static string ToBase64(Bitmap bmp, System.Drawing.Imaging.ImageFormat format)
  13. {
  14. try
  15. {
  16. MemoryStream ms = new MemoryStream();
  17. bmp.Save(ms, format);
  18. byte[] arr = new byte[ms.Length];
  19. ms.Position = 0;
  20. ms.Read(arr, 0, (int)ms.Length);
  21. ms.Close();
  22. String strbaser64 = Convert.ToBase64String(arr);
  23. return strbaser64;
  24. }
  25. catch (Exception ex)
  26. {
  27. throw new Exception("ImgToBase64String 转换失败 Exception:" + ex.Message);
  28. }
  29. }
  30. }
  31. }