Example #1
0
        private SnippWindow createWindowFromJSON(JToken item)
        {
            var win   = new SnippWindow(this);
            var b64   = item["Image64"].ToString();
            var bytes = Convert.FromBase64String(b64);
            var vm    = (win.DataContext as DraggableViewModel);

            System.Drawing.Bitmap bmp;
            BitmapImage           img = new BitmapImage();

            using (var stream = new MemoryStream(bytes))
            {
                img.BeginInit();
                img.CacheOption  = BitmapCacheOption.OnLoad;
                img.StreamSource = stream;
                img.EndInit();
            }

            vm.IsUnsaved        = false;
            vm.Opacity          = float.Parse(item["Opacity"].ToString());
            vm.ImageSource      = item["ImageSource"].ToString();
            vm.PosTop           = Int32.Parse(item["PosTop"].ToString());
            vm.Image64          = b64;
            vm.PosLeft          = Int32.Parse(item["PosLeft"].ToString());
            vm.Tags             = JsonConvert.DeserializeObject <ObservableCollection <Tag> >(item["Tags"].ToString());
            win.imgSrc.Source   = img;
            win.Width           = img.Width;
            win.Height          = img.Height;
            vm.UniqueIdentifier = b64.GetHashCode();
            return(win);
        }
Example #2
0
        private void Window_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (rect == null)
            {
                return;
            }

            if (rect.Width * rect.Height > 4)
            {
                //imgCapture.Source = null;
                var dt = new System.Windows.Threading.DispatcherTimer();
                //ToggleWindow();
                var x = RectStart.X;
                var y = RectStart.Y;
                var w = RectSize.Width;
                var h = RectSize.Height;

                var location = BitmapLocation;

                ToggleWindow();
                Task.Delay(5).ContinueWith(task =>
                {
                    DoTakeScreenShot(x, y, w, h, location); // Maybe set a timer to minimize and reactivate window for a few millisecs
                    _counter++;
                }).Wait();

                //TODO Clean shit up
                var oldOp = this.Opacity;
                this.Opacity = 0.0f;
                ToggleWindow();
                BitmapImage img = new BitmapImage();
                img.BeginInit();
                img.CacheOption = BitmapCacheOption.OnLoad;
                img.UriSource   = new Uri(location);
                img.EndInit();
                ctxCanvas.Children.Remove(rect);
                rect = null;

                var win = new SnippWindow(this);
                win.imgSrc.Source = img;
                win.Width         = img.Width;
                win.Height        = img.Height;
                win.Show();
                win.Focus();
                ((DraggableViewModel)win.DataContext).BitmapImage      = img;
                ((DraggableViewModel)win.DataContext).Image64          = BitmapImageToBase64(img);
                ((DraggableViewModel)win.DataContext).UniqueIdentifier = ((DraggableViewModel)win.DataContext).Image64.GetHashCode();
                ((DraggableViewModel)win.DataContext).ImageSource      = location;
                ((DraggableViewModel)win.DataContext).ImgHeight        = img.Height;
                ((DraggableViewModel)win.DataContext).ImgWidth         = img.Width;
                win.tagName.Focus();
                _windows.Add(win);
                ToggleWindow();
                this.Opacity = oldOp;
                //CurrentImage = img;
            }
        }
Example #3
0
        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = this;
            _windows         = new List <Window>();
            _searchResult    = new List <Window>();

            if (File.Exists(SnippWriter.HistoryFile))
            {
                var text = File.ReadAllText(SnippWriter.HistoryFile);
                var jobj = JArray.Parse(text);

                foreach (var item in jobj)
                {
                    SnippWindow win = createWindowFromJSON(item);
                    win.Show();
                    win.Focus();
                    _windows.Add(win);
                    Console.WriteLine();
                }
            }
        }
Example #4
0
 public void onSnippCLosed(SnippWindow win)
 {
     _windows.Remove(win);
 }