private void ShowFaceAlarmInfo(FaceAlarmInfo faceObj) { CardFaceAlarmItem itemInfo = new CardFaceAlarmItem(); itemInfo.ShowImage = MongoHelper.GetInstance().GetImageFileByName(faceObj.HitImageName); itemInfo.ShowImage2 = MongoHelper.GetInstance().GetImageFileByName(faceObj.AlarmImageName); itemInfo.PassTime = "时间:" + Convert.ToDateTime(faceObj.CreateTime.AsDateTime.AddHours(8)).ToString("yyyy-MM-dd HH:mm:ss"); itemInfo.CrossName = "比分:" + faceObj.ThresholdResult; try { this.Invoke(new ShowAlarmEventHandler(ShowAlertDialog), itemInfo); } catch { } }
private void ShowAlertDialog(CardFaceAlarmItem cardItem) { AlertInfo info = new AlertInfo("提示", cardItem.PassTime + " " + cardItem.CrossName); //AlertInfo info = new AlertInfo("", ""); info.Image = cardItem.ShowImage; Image frame = (Image)cardItem.ShowImage.Clone(); Image playbutton = (Image)cardItem.ShowImage2.Clone(); using (frame) { int width = 0; int height = 0; if (frame.Width > playbutton.Width) { width = frame.Width * 2; height = frame.Height > playbutton.Height ? frame.Height : playbutton.Height; var bitmap = new Bitmap(width, height); { using (var canvas = Graphics.FromImage(bitmap)) { canvas.InterpolationMode = InterpolationMode.HighQualityBicubic; canvas.DrawImage(frame, new Rectangle(0, 0, frame.Width, frame.Height), new Rectangle(0, 0, frame.Width, frame.Height), GraphicsUnit.Pixel); canvas.DrawImage(playbutton, new Rectangle(bitmap.Width / 2 + (bitmap.Width / 2 - playbutton.Width) / 2, (bitmap.Height - playbutton.Height) / 2, playbutton.Width, playbutton.Height), new Rectangle(0, 0, playbutton.Width, playbutton.Height), GraphicsUnit.Pixel); canvas.Save(); } try { info.Image = ((Image)bitmap).GetThumbnailImage(300, 200, () => false, IntPtr.Zero);; //bitmap.Save(/*somekindofpath*/, // System.Drawing.Imaging.ImageFormat.Jpeg); } catch (Exception ex) { } } } else { width = playbutton.Width * 2; height = frame.Height > playbutton.Height ? frame.Height : playbutton.Height; var bitmap = new Bitmap(width, height); { using (var canvas = Graphics.FromImage(bitmap)) { canvas.InterpolationMode = InterpolationMode.HighQualityBicubic; canvas.DrawImage(frame, new Rectangle((bitmap.Width / 2 - frame.Width) / 2, (bitmap.Height - frame.Height) / 2, frame.Width, frame.Height), new Rectangle(0, 0, frame.Width, frame.Height), GraphicsUnit.Pixel); canvas.DrawImage(playbutton, new Rectangle(playbutton.Width, 0, playbutton.Width, playbutton.Height), new Rectangle(0, 0, playbutton.Width, playbutton.Height), GraphicsUnit.Pixel); canvas.Save(); } try { //bitmap.Save(@"C:\1.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); info.Image = ((Image)bitmap).GetThumbnailImage(300, 200, () => false, IntPtr.Zero); } catch (Exception ex) { } } } } //info.Image = CombineBitmap(m_ListImage);// cardItem.ShowImage; alertControl1.Show(this.FindForm(), info); try { string alarmFile = Application.StartupPath + "\\BUZZ.WAV"; if (File.Exists(alarmFile)) { soundPlayer.Dispose(); soundPlayer = new SoundPlayer(); soundPlayer.SoundLocation = alarmFile; soundPlayer.Load(); soundPlayer.Play(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }