Example #1
0
 private void SaveCompleteEventFun(object sender, SaveImageCompleteInfo e)
 {
     if (SaveCompleteEvent != null)
     {
         SaveCompleteEvent(sender, e);
     }
 }
Example #2
0
 public virtual void SaveImageByFullName(Bitmap image, string imageFullName)
 {
     if (IsSaveImage == false)
     {
         return;
     }
     try
     {
         if (IsFilePathExist(Path.GetDirectoryName(imageFullName)))  //判断文件路径是否存在
         {
             Bitmap saveImage = image.Clone() as Bitmap;
             //判断队列中的数量是否大于0或存图是否正忙
             if (myImageQueue.Count > 0)
             {
                 PushImageToQueue(saveImage, imageFullName);
             }
             else
             {
                 SavaimageMethod(saveImage, imageFullName);
             }
         }
     }
     catch (Exception ex)
     {
         if (SaveCompleteEvent != null)
         {
             SaveImageCompleteInfo saveImageCompleteInfo = new SaveImageCompleteInfo(ex.ToString());
             saveImageCompleteInfo.SaveCompleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
             SaveCompleteEvent(this, saveImageCompleteInfo);   //保存完成事件
         }
         Console.WriteLine(ex.ToString());
         throw ex;
     }
 }
Example #3
0
 protected void SavaimageMethod(Bitmap image, string fileName)
 {
     try
     {
         Task saveTask = new Task(new Action(() =>
         {
             if (_saveType == SaveImageType.BMP)
             {
                 image.Save(fileName, ImageFormat.Bmp);
             }
             else
             {
                 image.Save(fileName, ImageFormat.Jpeg);
             }
             ImageName = System.IO.Path.GetFileName(fileName);
             if (SaveCompleteEvent != null)
             {
                 SaveImageCompleteInfo saveImageCompleteInfo = new SaveImageCompleteInfo(true);
                 saveImageCompleteInfo.ImageFullName         = fileName;
                 saveImageCompleteInfo.SaveCompleteTime      = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                 SaveCompleteEvent(this, saveImageCompleteInfo);   //保存完成事件
             }
         }));
         saveTask.Start();
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
         throw ex;
     }
 }
Example #4
0
 /// <summary>
 /// 保存bitmap类型的图片
 /// </summary>
 /// <param name="image"></param>
 public virtual string Save(Bitmap image, string imageName)
 {
     if (IsSaveImage == false)
     {
         return(null);
     }
     try
     {
         if (IsFilePathExist(SavePath))  //判断文件路径是否存在
         {
             if (SaveType == SaveImageType.NONE)
             {
                 return(null);
             }
             Bitmap saveImage = image.Clone() as Bitmap;
             //检查输入图像名称的合法性
             CheckImageNameValidity(imageName);
             string filename = JudgementImageType(MakeImageName(imageName));
             //判断队列中的数量是否大于0或存图是否正忙
             if (myImageQueue.Count > 0)
             {
                 PushImageToQueue(saveImage, filename);
                 return(filename);
             }
             else
             {
                 SavaimageMethod(saveImage, filename);
                 return(filename);
             }
         }
         else
         {
             return("Err");
         }
     }
     catch (Exception ex)
     {
         if (SaveCompleteEvent != null)
         {
             SaveImageCompleteInfo saveImageCompleteInfo = new SaveImageCompleteInfo(ex.ToString());
             saveImageCompleteInfo.SaveCompleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
             SaveCompleteEvent(this, saveImageCompleteInfo);   //保存完成事件
         }
         Console.WriteLine(ex.ToString());
         return("Err");
     }
 }