123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- using CCDCount.DLL;
- using CCDCount.DLL.SqlDataClass;
- using CCDCount.MODEL.ConfigModel;
- using CCDCount.MODEL.ShuLiModel;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Markup;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace CCDCountWpf.WpfPage
- {
- /// <summary>
- /// HistoryDataPage.xaml 的交互逻辑
- /// </summary>
- public partial class HistoryDataPage : Page
- {
- private static ActionMesSqliteDataClass actionMesSqliteDataClass = null;
- int DataStartLine = 0;
- private int PageHeight = 2000;
- public HistoryDataPage()
- {
- InitializeComponent();
- DataContext = ShowMessageBus.ShowBinding;
- actionMesSqliteDataClass = new ActionMesSqliteDataClass($"{AppDomain.CurrentDomain.BaseDirectory}DATA\\ActiveObjectData\\Cam{MessageBus.MainThreadS[0].cameraConfig.CamerNo}\\ActiveObjectData{DateTime.Now:yyyyMMdd}.db");
- actionMesSqliteDataClass.GetAllActionMinStartMaxEndLine(out int num, out int StartLine, out int EndLine);
- ShowMessageBus.ShowBinding.HistoryImageCount = (EndLine - StartLine)/PageHeight;
- DataStartLine = StartLine;
- UpDateShowBinding();
- }
- private void PreviousBtn_Click(object sender, RoutedEventArgs e)
- {
- if (ShowMessageBus.ShowBinding.HistoryImageNum <= 1)
- {
- MessageBox.Show("已经是第一页");
- return;
- }
- ShowMessageBus.ShowBinding.HistoryImageNum -= 1;
- UpDateShowBinding();
- }
- private void NextBtn_Click(object sender, RoutedEventArgs e)
- {
- if (ShowMessageBus.ShowBinding.HistoryImageNum >= ShowMessageBus.ShowBinding.HistoryImageCount)
- {
- MessageBox.Show("已经是最后一页");
- return;
- }
- ShowMessageBus.ShowBinding.HistoryImageNum += 1;
- UpDateShowBinding();
- }
- private void UpDateShowBinding()
- {
- Stopwatch stopwatch = Stopwatch.StartNew();
- BitmapImage ShowBitMap = null;
- Bitmap BitmapImage = null;
- List<ActiveObjectClass> ShowResult = actionMesSqliteDataClass.GetActiveObjectForPage((ShowMessageBus.ShowBinding.HistoryImageNum - 1) * PageHeight + DataStartLine, ShowMessageBus.ShowBinding.HistoryImageNum * PageHeight + DataStartLine);
- if (ShowResult.Count > 0)
- {
- int ThisImageStartLine = (int)ShowResult.Min(o => o.StartLine);
- int ImageHeight = (int)(ShowResult.Max(o => o.LastSeenLine) - ShowResult.Min(o => o.StartLine));
- BitmapImage = new Bitmap(4096, ImageHeight <= PageHeight ? PageHeight : ImageHeight);
- using (Graphics g = Graphics.FromImage(BitmapImage))
- {
- g.Clear(System.Drawing.Color.White);
- var redPen = new System.Drawing.Pen(System.Drawing.Color.Red, 1);
- var bluePen = new System.Drawing.Pen(System.Drawing.Color.FromArgb(0, 146, 255), 1);
- var GreenPen = new System.Drawing.Pen(System.Drawing.Color.SeaGreen, 5);
- foreach (var item in ShowResult)
- {
- int roix = item.MinStartCol - 5;
- int roiy = (int)(item.StartLine - ThisImageStartLine) - 5;
- int roiheight = (int)(item.LastSeenLine - (long)item.StartLine) + 10;
- int roiwidth = item.MaxEndCol - item.MinStartCol + 10;
- g.DrawRectangle(GreenPen, new System.Drawing.Rectangle(roix, roiy, roiwidth, roiheight));
- Font font = new Font("Arial", 40);
- g.DrawString(item.Num.ToString(), font, System.Drawing.Brushes.Black, new System.Drawing.Point(roix - 50 * item.Num.ToString().Length, roiy - 20));
- foreach (var item1 in item.RowsData)
- {
- int yPos = (int)(item1.RowsCol - ThisImageStartLine);
- g.DrawLine(item.StateCode == 0 ? bluePen : redPen, new System.Drawing.Point(item1.StartCol, yPos), new System.Drawing.Point(item1.EndCol, yPos));
- }
- }
- }
- }
- else
- {
- BitmapImage = new Bitmap(4096, PageHeight);
- using (Graphics g = Graphics.FromImage(BitmapImage))
- {
- g.Clear(System.Drawing.Color.White);
- }
- }
- Application.Current.Dispatcher.InvokeAsync(() =>
- {
- ShowBitMap = ConvertToBitmapImage(BitmapImage);
- ShowMessageBus.ShowBinding.HistoryImage = ShowBitMap;
- });
- stopwatch.Stop();
- Console.WriteLine($"{stopwatch.ElapsedMilliseconds}ms");
- }
- // Bitmap 转 BitmapImage 的辅助方法
- private BitmapImage ConvertToBitmapImage(Bitmap bitmap)
- {
- using (MemoryStream memory = new MemoryStream())
- {
- bitmap.Save(memory, System.Drawing.Imaging.ImageFormat.Png);
- memory.Position = 0;
- var bitmapImage = new BitmapImage();
- bitmapImage.BeginInit();
- bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
- bitmapImage.StreamSource = memory;
- bitmapImage.EndInit();
- return bitmapImage;
- }
- }
- private void SkipBtn_Click(object sender, RoutedEventArgs e)
- {
- UpDateShowBinding();
- }
- }
- }
|