Beispiel #1
0
        public GamerReflectionUi()
        {
            var files = System.IO.Directory.GetFiles(ApplicationHlp.MapPath("Analyze"))
                        .OrderBy(file => ConvertHlp.ToDouble(System.IO.Path.GetFileNameWithoutExtension(file)))
                        .ToArray();

            string selectedFile   = null;
            Bitmap selectedBitmap = null;

            Mat[] selectedChannels = null;

            h.Protocol().Register("img",
                                  (url, context) =>
            {
                var urlPath     = url.Trim('/', '\\').Substring((context.ProtocolPrefix + "://").Length);
                var ss          = urlPath.Split('.');
                var imgFilename = ss.FirstOrDefault();
                var kind        = ss.ElementAtOrDefault(1);
                var imgPath     = files.FirstOrDefault(file => System.IO.Path.GetFileNameWithoutExtension(file) == imgFilename);
                switch (kind)
                {
                case "source":
                    return(System.IO.File.ReadAllBytes(imgPath));

                case "h":
                    return(selectedChannels.Else_Empty().ElementAtOrDefault(0)._f(_ => _.Resize(0.5).ToBitmap().ToBytes()));

                case "s":
                    return(selectedChannels.Else_Empty().ElementAtOrDefault(1)._f(_ => _.Resize(0.5).ToBitmap().ToBytes()));

                case "v":
                    return(selectedChannels.Else_Empty().ElementAtOrDefault(2)._f(_ => _.Resize(0.5).ToBitmap().ToBytes()));
                }
                return(null);
            }
                                  );

            InitializeComponent();


            //var filename = "unknown.bmp";


            //Console.WriteLine(img);



            var points = new CheckPoint[] { };

            new SoftTech.Wui.HDesktopSynchronizer(webBrowser1, () => HView(files, selectedFile, selectedBitmap), json =>
            {
                try
                {
                    switch (json.JPath("data", "command").ToString_Fair())
                    {
                    case "select-file":
                        {
                            var path     = json.JPath("data", "file").ToString_Fair();
                            selectedFile = path;

                            var img_data     = System.IO.File.ReadAllBytes(path);
                            var bitmap       = (Bitmap)Bitmap.FromStream(new System.IO.MemoryStream(img_data));
                            selectedChannels = new Mat(bitmap.ToIplImage(), true).Split();
                        }
                        break;

                    //case "select":
                    //  {
                    //    switch (json.JPath("event", "type").ToString_Fair())
                    //    {
                    //      case "mousemove":
                    //        x = ConvertHlp.ToInt(json.JPath("event", "clientX"));
                    //        y = ConvertHlp.ToInt(json.JPath("event", "clientY"));
                    //        if (x != null && y != null && x >= 0 && y >= 0 && x < img.Width && y < img.Height)
                    //          color = img.Get<byte>(y.Value, x.Value);
                    //        break;
                    //      case "mousedown":
                    //        {
                    //          var _x = ConvertHlp.ToInt(json.JPath("event", "clientX"));
                    //          var _y = ConvertHlp.ToInt(json.JPath("event", "clientY"));
                    //          if (_x != null && _y != null && _x >= 0 && _y >= 0 && _x < img.Width && _y < img.Height)
                    //          {
                    //            var _color = bitmap.GetPixel(_x.Value, _y.Value);
                    //            points = new[] { new CheckPoint(_x.Value, _y.Value, (uint)_color.ToArgb()) }.Concat(points).Take(10).ToArray();
                    //          }
                    //        }
                    //        break;
                    //    }
                    //  }
                    //  break;
                    default:
                        Console.WriteLine(json);
                        break;
                    }
                }
                catch (Exception exc)
                {
                    Console.WriteLine(exc);
                }
            });
        }
 public static double?ToDouble(string s)
 {
     return(ConvertHlp.ToDouble(s));
 }