示例#1
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();
                    }));
                });
            }
        }
示例#2
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();
                    }));
                });
            }
        }
示例#3
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);
            }
        }