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; }
public static void ShowScan(string imgPath) { if (!System.IO.File.Exists(imgPath)) { return; } bool isCreate; ImageScanWindow scan = CreateOrActiveWindow(imgPath, out isCreate); if (isCreate) { BitmapImage img = new BitmapImage(new Uri(imgPath, UriKind.RelativeOrAbsolute)); SetProperty(imgPath, scan, img); } else { Task.Delay(50).ContinueWith(task => { scan.Dispatcher.Invoke(new Action(() => { if (scan.WindowState == WindowState.Minimized) { scan.WindowState = WindowState.Normal; } scan.Activate(); })); }); } }
public static void ShowScan(ImageSource img) { if (img == null) { return; } bool isCreate; ImageScanWindow scan = CreateOrActiveWindow(img.ToString(), out isCreate); if (isCreate) { SetProperty(img.ToString(), scan, img); } else { Task.Delay(50).ContinueWith(task => { scan.Dispatcher.Invoke(new Action(() => { if (scan.WindowState == WindowState.Minimized) { scan.WindowState = WindowState.Normal; } scan.Activate(); })); }); } }
private static void SetProperty(string imgPath, ImageScanWindow scan, ImageSource imgSouce) { if (imgSouce != null && imgSouce.Width > 0 && imgSouce.Height > 0) { _originalImageWidth = imgSouce.Width; _originalImageHeight = imgSouce.Height; 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.2); w = Math.Min(w, PrimaryScreen.MaxAreaWidth * 0.8); h = Math.Max(h, PrimaryScreen.MaxAreaHeight * 0.2); h = Math.Min(h, PrimaryScreen.MaxAreaHeight * 0.8); scan.img.Width = w; scan.img.Height = h; scan.Width = w + 20; scan.Height = h + 86; //scan.img.Source = imgSouce; scan.Show(); if (imgPath.ToUpper().EndsWith(".GIF")) { Task.Delay(10).ContinueWith(task => { scan.Dispatcher.Invoke(new Action(() => { scan.img.FilePath = imgPath; })); }); } else { scan.img.FilePath = imgPath; } HistoryWIN.Add(scan._key = imgPath, scan); } }