Esempio n. 1
0
        static void SetScale(ImageScanWindow scan)
        {
            double scaleX = 1d;

            if (scan.rotate.Angle == 90 || scan.rotate.Angle == 270)
            {
                if (_originalImageWidth > scan.gridScan.ActualHeight)
                {
                    scaleX = Math.Round(scan.gridScan.ActualHeight / _originalImageWidth, 1);
                }
                else if (_originalImageHeight > scan.gridScan.ActualWidth)
                {
                    scaleX = Math.Round(scan.gridScan.ActualWidth / _originalImageHeight, 1);
                }
            }
            else
            {
                if (_originalImageWidth > scan.gridScan.ActualWidth)
                {
                    scaleX = Math.Round(scan.gridScan.ActualWidth / _originalImageWidth, 1);
                }
                else if (_originalImageHeight > scan.gridScan.ActualHeight)
                {
                    scaleX = Math.Round(scan.gridScan.ActualHeight / _originalImageHeight, 1);
                }
            }

            scan.Scale        = scaleX;
            scan.Scale        = scan.Scale < 0.1 ? 0.1 : scan.Scale;
            scan.scale.ScaleX = scan.scale.ScaleY = scan.Scale;
        }
Esempio n. 2
0
 public static ImageScanWindow CreateOrActiveWindow(out bool isCreate)
 {
     if (_current != null)
     {
         isCreate = false;
         return(_current);
     }
     else
     {
         isCreate = true;
         return(_current = new ImageScanWindow());
     }
 }
Esempio n. 3
0
        private void ImageScanWindow_Closed(object sender, EventArgs e)
        {
            _current              = null;
            this.PreviewKeyDown  -= ImageScanWindow_PreviewKeyDown;
            this.thumb.DragDelta -= Thumb_DragDelta;
            this.Closed          -= ImageScanWindow_Closed;
            this.Loaded          -= ImageScanWindow_Loaded;

            Views.ChildWindows.AppendWindow.AutoClose = false;
            App.Current.MainWindow.Activate();
            Views.ChildWindows.AppendWindow.AutoClose = true;

            _sources = null;
            this.img.Dispose();
        }
Esempio n. 4
0
        public static void ShowScan(IList <MessageModel> list, MessageModel target)
        {
            if (list == null || list.Count == 0 || target == null)
            {
                return;
            }

            if (_current != null)
            {
                _current.Close();
            }

            ImageScanWindow scan = _current = new ImageScanWindow();

            scan.img.Source = null;
            scan._sources   = list;
            scan._target    = target;
            scan.ShowCurrent();
        }
Esempio n. 5
0
        public static void ShowScan(string imgPath)
        {
            if (imgPath != IMAssets.ImageDeal.DefaultHeadImage && !System.IO.File.Exists(imgPath))
            {
                return;
            }
            bool isCreate;

            if (_current != null)
            {
                _current.Close();
                _current = null;
            }
            ImageScanWindow scan = CreateOrActiveWindow(out isCreate);

            scan.rotate.Angle   = 0;
            scan.scale.ScaleX   = scan.scale.ScaleY = 1;
            scan.img.Visibility = Visibility.Visible;
            BitmapImage img = new BitmapImage(new Uri(imgPath, UriKind.RelativeOrAbsolute));

            SetProperty(imgPath, scan, img, false);

            if (isCreate)
            {
                scan.ShowCurrent(imgPath);
            }
            else
            {
                Task.Delay(50).ContinueWith(task =>
                {
                    scan.Dispatcher.Invoke(new Action(() =>
                    {
                        if (scan.WindowState == WindowState.Minimized)
                        {
                            scan.WindowState = WindowState.Normal;
                        }
                        scan.Activate();
                    }));
                });
            }
        }
Esempio n. 6
0
        public static void ShowScan(ImageSource img)
        {
            if (img == null)
            {
                return;
            }
            bool isCreate;

            ImageScanWindow scan = CreateOrActiveWindow(out isCreate);

            scan.rotate.Angle = 0;
            scan.scale.ScaleX = scan.scale.ScaleY = 1;

            scan.img.Visibility = Visibility.Visible;
            SetProperty(img.ToString(), scan, img, false);
            string imgPath = img.ToString().Contains("file:///") ? img.ToString().Remove(0, "file:///".Length) : img.ToString();

            if (isCreate)
            {
                scan.ShowCurrent(imgPath);
            }
            else
            {
                Task.Delay(50).ContinueWith(task =>
                {
                    scan.Dispatcher.Invoke(new Action(() =>
                    {
                        if (scan.WindowState == WindowState.Minimized)
                        {
                            scan.WindowState = WindowState.Normal;
                        }
                        scan.Activate();
                    }));
                });
            }
        }
Esempio n. 7
0
        private static void SetProperty(string imgPath, ImageScanWindow scan, ImageSource imgSouce, bool isResize = true)
        {
            if (imgSouce != null && imgSouce.Width > 0 && imgSouce.Height > 0)
            {
                _originalImageWidth  = imgSouce.Width;
                _originalImageHeight = imgSouce.Height;
                if (_originalImageHeight > 450 || _originalImageWidth > 650)
                {
                    double w = imgSouce.Width * 1.1, h = imgSouce.Height * 1.1;

                    //scan.Width = w + 60; scan.Height = h + 60;

                    w = Math.Max(w, PrimaryScreen.MaxAreaWidth * 0.4);
                    w = Math.Min(w, PrimaryScreen.MaxAreaWidth * 0.8);

                    h = Math.Max(h, PrimaryScreen.MaxAreaHeight * 0.4);
                    h = Math.Min(h, PrimaryScreen.MaxAreaHeight * 0.8);

                    if (_originalImageWidth > 650)
                    {
                        scan.img.Width = w;
                    }
                    else
                    {
                        scan.img.Width = _originalImageWidth;
                    }
                    if (_originalImageHeight > 450)
                    {
                        scan.img.Height = h;
                    }
                    else
                    {
                        scan.img.Height = _originalImageHeight;
                    }

                    scan.Width  = scan.img.Width + 30;
                    scan.Height = scan.img.Height + 96;

                    scan.Left = (PrimaryScreen.MaxAreaWidth - scan.Width) / 2;
                    scan.Top  = (PrimaryScreen.MaxAreaHeight - scan.Height) / 2;
                }
                else
                {
                    scan.img.Width  = _originalImageWidth;
                    scan.img.Height = _originalImageHeight;
                    scan.Width      = 650;
                    scan.Height     = _originalImageHeight + 90;
                    scan.Left       = (PrimaryScreen.MaxAreaWidth - scan.Width) * 0.5;
                    scan.Top        = (PrimaryScreen.MaxAreaHeight - scan.Height) * 0.5;
                }
                //scan.img.Source = imgSouce;
                //scan.Show();
                //if (!File.Exists(imgPath)) return;
                if (imgPath.ToUpper().EndsWith(".GIF"))
                {
                    Task.Delay(10).ContinueWith(task =>
                    {
                        scan.Dispatcher.Invoke(new Action(() =>
                        {
                            scan.img.FilePath = imgPath;
                        }));
                    });
                }
                else
                {
                    scan.img.FilePath = imgPath;
                }
            }
        }
Esempio n. 8
0
        private void SetImage(string imgPath, bool isImgExceed = false)
        {
            bool            isCreate;
            ImageScanWindow scan = CreateOrActiveWindow(out isCreate);

            scan.Show();
            //Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, new Action(() =>
            //{
            if (_currentPath != imgPath)
            {
                this.img.Dispose();
                AsyncHandler.CallFuncWithUI(System.Windows.Application.Current.Dispatcher, () =>
                {
                    try
                    {
                        scan.Dispatcher.Invoke(new Action(() =>
                        {
                            scan.loading.Visibility = Visibility.Visible;
                        }));
                        //this.img.Visibility = Visibility.Collapsed;
                        //this.tbInfo.Text = "图片加载中...";
                        //BitmapImage img = new BitmapImage(new Uri(imgPath, UriKind.RelativeOrAbsolute));

                        if (isImgExceed)
                        {
                            App.Current.Dispatcher.Invoke(() =>
                            {
                                this.img.Visibility     = Visibility.Visible;
                                scan.loading.Visibility = Visibility.Collapsed;
                                BitmapImage img         = new BitmapImage();
                                img.BeginInit();
                                img.CacheOption = BitmapCacheOption.OnLoad;
                                img.UriSource   = new Uri(IMAssets.ImageDeal.ImgLoadFail);
                                img.EndInit();
                                img.Freeze();
                                this.tbInfo.Text = "图片已过期!";
                                this.img.Source  = img;
                                //SetProperty(imgPath, scan, img, false);
                                SetState(true);
                            });
                            return(null);
                        }
                        else
                        {
                            var bitmap = new BitmapImage();
                            bitmap.BeginInit();

                            bitmap.CacheOption  = BitmapCacheOption.OnLoad;
                            bitmap.StreamSource = new MemoryStream(File.ReadAllBytes(imgPath));
                            //bitmap.StreamSource = new MemoryStream(ImageHelper.ImageToBytes(path));
                            bitmap.EndInit();
                            bitmap.Freeze();
                            return(bitmap);
                        }
                    }
                    catch
                    {
                        try
                        {
                            BitmapImage img = new BitmapImage();
                            img.BeginInit();
                            img.CacheOption = BitmapCacheOption.OnLoad;
                            if (imgPath == IMAssets.ImageDeal.DefaultHeadImage)
                            {
                                img.UriSource = new Uri(imgPath);
                            }
                            else
                            {
                                img.StreamSource = new MemoryStream(ImageHelper.ImageToBytes(imgPath));
                            }
                            img.EndInit();
                            img.Freeze();
                            return(img);
                        }
                        catch
                        {
                            App.Current.Dispatcher.Invoke(() =>
                            {
                                this.img.Visibility     = Visibility.Collapsed;
                                scan.loading.Visibility = Visibility.Collapsed;
                                IMClient.Helper.MessageHelper.LoadImgContent(_target);
                                _currentPath     = imgPath;
                                this.Title       = this.tbName.Text = System.IO.Path.GetFileName(imgPath);
                                this.tbInfo.Text = "加载失败!";
                                SetState(true);
                            });
                            return(null);
                        }
                    }
                },
                                            (ex, data) =>
                {
                    if (data == null)
                    {
                        return;
                    }
                    scan.Dispatcher.Invoke(new Action(() =>
                    {
                        loading.Visibility = Visibility.Collapsed;
                    }));
                    SetProperty(imgPath, scan, data, false);
                    _currentPath = imgPath;
                    this.Title   = this.tbName.Text = System.IO.Path.GetFileName(imgPath);
                    //Task.Delay(30).ContinueWith(task =>
                    //{
                    //    scan.Dispatcher.Invoke(new Action(() =>
                    //    {
                    if (scan.WindowState == WindowState.Minimized)
                    {
                        scan.WindowState = WindowState.Normal;
                    }
                    SetState(true);
                    scan.Activate();
                    //}));
                    //});
                    //}));
                });
            }
            else
            {
                SetState(true);
            }
        }