| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- using Common;
- using MeterPlugInLibrary;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace CarMeterSystem.OptionCls
- {
- /// <summary>
- /// 截图调用类
- /// </summary>
- public class CameraShotCls
- {
- private Log lg = Log.GetInstance(); //写日志
- public void Connection()
- {
- try
- {
- foreach (DhCameraShot shot in CarCache.cameraShots)
- {
- shot.Connection();
- }
- }
- catch (Exception ex)
- {
- lg.WriteLog(39, ex.Message);
- }
- }
- public void Close()
- {
- try
- {
- foreach (DhCameraShot shot in CarCache.cameraShots)
- {
- shot.Close();
- }
- }
- catch (Exception ex)
- {
- lg.WriteLog(39, ex.Message);
- }
- }
- /// <summary>
- /// 截图
- /// </summary>
- /// <param name="actualFirstNo">作业编号</param>
- public void CapPic(string actualFirstNo)
- {
- try
- {
- int iCnt = 1; //抓拍摄像头配置顺序必须是前面2个
- foreach (DhCameraShot shot in CarCache.cameraShots)
- {
- //放在tempImg文件夹下面就进行图片的压缩操作,否则不进行图片压缩
- //shot.CapPic(iCnt < 3 ? 0 : 1, PbCache.path + string.Format("\\imgShort\\tempImg\\{0}_{1}_{2}.jpg", PbCache.sportInfo.baseSpotNo, "C" + actualFirstNo, iCnt));
- shot.CapPic(iCnt < 2 ? 0 : 1, PbCache.path + string.Format("\\imgShort\\formalImg\\{0}_{1}_{2}.jpg", PbCache.sportInfo.baseSpotNo, "C" + actualFirstNo, iCnt));
- ZipFiles(PbCache.path + string.Format("\\imgShort\\formalImg\\{0}_{1}_{2}.jpg", PbCache.sportInfo.baseSpotNo, "C" + actualFirstNo, iCnt));
-
- // 第一次抓拍为仪表重量
- //if(iCnt == 1)
- //{
- // Log.GetInstance().WriteLog(35, "完成仪表拍照 成功标识:" + PbCache.shotSuccess.ToString() + "车号:" + PbCache.lockCarNo + ";重量:" + PbCache.lockWgt + ";时间:" + DateTime.Now.ToLongTimeString());
- //}
- iCnt++;
- }
- }
- catch (Exception ex)
- {
- lg.WriteLog(39,ex.Message);
- }
-
- }
- private void ZipFiles(String fn)
- {
-
- ImageZip iz = new ImageZip();
- if (string.IsNullOrEmpty(fn)) return;
- if (!File.Exists(fn)) return;
- //临时目录图片压缩后存储与正式目录
- string jpgFile = fn.Replace("tempImg", "temp");
- Image img = ImageZip.BytesToBitmap(ImageZip.ZipImageByte(fn));
- if (img != null)
- {
-
- //压缩图片并保存
- if(img.Width > AppConfigCache.imgWidth && img.Height > AppConfigCache.imgHeight)
- {
- img.Save(jpgFile);
- // BourneCao 20221220 使用以下方法继续压缩,比原图还要大
- //iz.ResourceImage = img;
- //iz.GetReducedImage(AppConfigCache.imgWidth, AppConfigCache.imgHeight).Save(jpgFile);
- }
- else
- {
- img.Save(jpgFile);
- }
- File.Delete(fn);//删除临时目录数据
- }
- //else
- //{
- // iz.ResourceImage = img;
- // //压缩图片并保存
- // iz.GetReducedImage(400, 400).Save(jpgFile);
- // //File.Move(fn, jpgFile);
- //}
- }
- /// <summary>
- /// 从硬盘录像机 进行截图
- /// </summary>
- /// <param name="actualFirstNo"></param>
- public void CapPicFromVideo(string actualFirstNo)
- {
- try
- {
- foreach (DhCameraShot shot in CarCache.cameraShots)
- {
- //放在tempImg文件夹下面就进行图片的压缩操作,否则不进行图片压缩
- //shot.CapPic(iCnt < 3 ? 0 : 1, PbCache.path + string.Format("\\imgShort\\tempImg\\{0}_{1}_{2}.jpg", PbCache.sportInfo.baseSpotNo, "C" + actualFirstNo, iCnt));
- bool shotSuccess = shot.CapPicFromVedio(PbCache.path + string.Format("\\imgShort\\formalImg\\{0}_{1}_", PbCache.sportInfo.baseSpotNo, "C" + actualFirstNo));
- PbCache.shotSuccess = shotSuccess;
- }
- }
- catch (Exception ex)
- {
- lg.WriteLog(39, ex.Message);
- }
- }
- /// <summary>
- /// 连接视频截图并关闭
- /// </summary>
- /// <param name="actualFirstNo">作业编号</param>
- public void CapMethod(string actualFirstNo)
- {
- Connection();
- CapPic(actualFirstNo);
- //CapPicFromVideo(actualFirstNo);
- Close();
- }
- }
- }
|