using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static MeterVision.FreeAi.FaImport;

namespace MeterVision.FreeAi
{
    public class FaImage
    {


        public static bool saveBigJpg(BigImage bigJpg,string fileName)
        {
            if(bigJpg.size_of_JPEG_data == 0)
            {
                Debug.Write("bigJpg dataSize error!");
                return false;
            }

            //if(bigJpg.image_height != FaConstant.IMAGE_HEIGHT || 
            //    bigJpg.image_width != FaConstant.IMAGE_WIDTH)
            //{
            //    Debug.Write("bigJpg width or heght erro!");
            //    return false;
            //}

            bool saveResult = false;
            try
            {
                //获取文件夹路径
                string directoryPath = Path.GetDirectoryName(fileName);

                //如果文件夹不存在，创建文件夹
                if (!Directory.Exists(directoryPath))
                {
                    Directory.CreateDirectory(directoryPath);
                }

                //保存文件
                //File.WriteAllBytes(fileName, bigJpg.JPEG_data);

                using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write))
                {
                    fs.Write(bigJpg.JPEG_data, 0, bigJpg.size_of_JPEG_data);
                }


                saveResult = true;
            }
            catch (Exception e)
            {
                Debug.Write(e.Message);
            }

            string strResult = string.Format("save {0} {1}", fileName, saveResult ? "success" : "fail");

            Debug.Write(strResult);

            return saveResult;
        }



        /////////////////////////////////////////////////////////////////
    }
}
