OCRVerifyMethod.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace OASystem.Domain.Dtos.Tencent
  7. {
  8. /// <summary>
  9. /// OCR Request Param Verify Method
  10. /// </summary>
  11. public static class OCRVerifyMethod
  12. {
  13. /// <summary>
  14. /// TencentOCR图片类型处理
  15. /// PNG、JPG、JPEG、BMP
  16. /// </summary>
  17. /// <param name="type"></param>
  18. /// <returns></returns>
  19. public static bool ImageType(string type)
  20. {
  21. string[] picBase64Array = type.Split(';');
  22. string picFormat = picBase64Array[0].Split('/')[1];
  23. if (picFormat.ToLower().Equals("png") || picFormat.ToLower().Equals("jpg") || picFormat.ToLower().Equals("jpeg") || picFormat.ToLower().Equals("bmp"))
  24. return true;
  25. return false;
  26. }
  27. /// <summary>
  28. /// TencentOCR图片大小处理
  29. /// 不能大于7MB
  30. /// </summary>
  31. /// <param name="type"></param>
  32. /// <returns></returns>
  33. public static bool ImageSize(string picBase64)
  34. {
  35. double strSize = 1024 * 1024 * 7;
  36. if (picBase64.Length < strSize)
  37. {
  38. return true;
  39. }
  40. return false;
  41. }
  42. }
  43. }