FaImage.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using static MeterVision.FreeAi.FaImport;
  9. namespace MeterVision.FreeAi
  10. {
  11. public class FaImage
  12. {
  13. public static bool saveBigJpg(BigImage bigJpg,string fileName)
  14. {
  15. if(bigJpg.size_of_JPEG_data == 0)
  16. {
  17. Debug.Write("bigJpg dataSize error!");
  18. return false;
  19. }
  20. //if(bigJpg.image_height != FaConstant.IMAGE_HEIGHT ||
  21. // bigJpg.image_width != FaConstant.IMAGE_WIDTH)
  22. //{
  23. // Debug.Write("bigJpg width or heght erro!");
  24. // return false;
  25. //}
  26. bool saveResult = false;
  27. try
  28. {
  29. //获取文件夹路径
  30. string directoryPath = Path.GetDirectoryName(fileName);
  31. //如果文件夹不存在,创建文件夹
  32. if (!Directory.Exists(directoryPath))
  33. {
  34. Directory.CreateDirectory(directoryPath);
  35. }
  36. //保存文件
  37. //File.WriteAllBytes(fileName, bigJpg.JPEG_data);
  38. using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write))
  39. {
  40. fs.Write(bigJpg.JPEG_data, 0, bigJpg.size_of_JPEG_data);
  41. }
  42. saveResult = true;
  43. }
  44. catch (Exception e)
  45. {
  46. Debug.Write(e.Message);
  47. }
  48. string strResult = string.Format("save {0} {1}", fileName, saveResult ? "success" : "fail");
  49. Debug.Write(strResult);
  50. return saveResult;
  51. }
  52. /////////////////////////////////////////////////////////////////
  53. }
  54. }