Exemplo n.º 1
0
        /// <summary>
        /// Show image or thumbnail preview on drag enter
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        internal static void Image_DragEnter(object sender, DragEventArgs e)
        {
            // Error handling
            if (!e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                return;
            }

            var files = e.Data.GetData(DataFormats.FileDrop, true) as string[];
            var check = Drag_Drop_Check(files);

            // Do nothing for invalid files
            if (!check.HasValue)
            {
                return;
            }

            if (!check.Value)
            {
                return;
            }

            // Check if same file
            if (files.Length == 1 && Pics.Count > 0)
            {
                if (files[0] == Pics[FolderIndex])
                {
                    return;
                }
            }

            // Tell that it's succeeded
            e.Effects = DragDropEffects.Copy;
            e.Handled = true;
            ShowTooltipMessage(Application.Current.Resources["DragOverString"] as string, true);

            // If no image, fix it to container
            if (LoadWindows.GetMainWindow.MainImage.Source == null)
            {
                LoadWindows.GetMainWindow.MainImage.Width  = LoadWindows.GetMainWindow.Scroller.ActualWidth;
                LoadWindows.GetMainWindow.MainImage.Height = LoadWindows.GetMainWindow.Scroller.ActualHeight;
            }
            else
            {
                // Save our image so we can swap back to it later if neccesary
                prevPicResource = LoadWindows.GetMainWindow.MainImage.Source;
            }

            // Load from preloader or thumbnails
            var thumb = Preloader.Contains(files[0]) ? Preloader.Load(files[0]) : GetBitmapSourceThumb(files[0]);

            if (thumb != null)
            {
                LoadWindows.GetMainWindow.MainImage.Source = thumb;
            }
        }
Exemplo n.º 2
0
        internal static void CopyBitmap()
        {
            if (Preloader.Contains(Pics[FolderIndex]))
            {
                Clipboard.SetImage(Preloader.Load(Pics[FolderIndex]));
            }
            else if (mainWindow.img.Source != null)
            {
                Clipboard.SetImage((BitmapSource)mainWindow.img.Source);
            }
            else
            {
                return;
            }

            ToolTipStyle("Copied Image to clipboard");
        }
Exemplo n.º 3
0
        internal static void CopyBitmap()
        {
            if (Pics.Count == 0 && LoadWindows.GetMainWindow.MainImage.Source != null)
            {
                Clipboard.SetImage((BitmapSource)LoadWindows.GetMainWindow.MainImage.Source);
            }
            else if (Preloader.Contains(Pics[FolderIndex]))
            {
                Clipboard.SetImage(Preloader.Load(Pics[FolderIndex]));
            }
            else if (LoadWindows.GetMainWindow.MainImage.Source != null)
            {
                Clipboard.SetImage((BitmapSource)LoadWindows.GetMainWindow.MainImage.Source);
            }
            else
            {
                return;
            }

            ShowTooltipMessage(Application.Current.Resources["FileCutMessage"]);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Show image or thumbnail preview on drag enter
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        internal static void Image_DragEnter(object sender, DragEventArgs e)
        {
            // Error handling
            if (!e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                return;
            }

            var files = e.Data.GetData(DataFormats.FileDrop, true) as string[];
            var check = Drag_Drop_Check(files);

            // Do nothing for invalid files
            if (!check.HasValue)
            {
                return;
            }

            // Tell that it's succeeded
            e.Effects     = DragDropEffects.Copy;
            isDraggedOver = e.Handled = true;
            ToolTipStyle(DragOverString, true);

            if (check.Value)
            {
                // If no image, fix it to container
                if (mainWindow.img.Source == null)
                {
                    mainWindow.img.Width  = mainWindow.Scroller.ActualWidth;
                    mainWindow.img.Height = mainWindow.Scroller.ActualHeight;
                }
                else
                {
                    // Save our image so we can swap back to it later if neccesary
                    prevPicResource = mainWindow.img.Source;
                }

                // Load from preloader or thumbnails
                mainWindow.img.Source = Preloader.Contains(files[0]) ? Preloader.Load(files[0]) : GetBitmapSourceThumb(files[0]);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Load thumbnail at current index
        /// or full image if preloaded.
        /// </summary>
        /// <returns></returns>
        internal static BitmapSource GetThumb()
        {
            var pic = Preloader.Load(Pics[FolderIndex]);

            if (pic == null)
            {
                if (picGallery != null)
                {
                    if (FolderIndex < picGallery.Container.Children.Count && picGallery.Container.Children.Count == Pics.Count)
                    {
                        var y = picGallery.Container.Children[FolderIndex] as PicGalleryItem;
                        pic = (BitmapSource)y.img.Source;
                    }
                    else
                    {
                        pic = GetWindowsThumbnail(Pics[FolderIndex]);

                        if (pic == null)
                        {
                            pic = GetBitmapSourceThumb(Pics[FolderIndex]);
                        }
                    }
                }
                else
                {
                    pic = GetWindowsThumbnail(Pics[FolderIndex]);

                    if (pic == null)
                    {
                        pic = GetBitmapSourceThumb(Pics[FolderIndex]);
                    }
                }
            }

            return(pic);
        }
Exemplo n.º 6
0
        internal static void Click(int id)
        {
            LoadWindows.GetMainWindow.Focus();

            if (Properties.Settings.Default.PicGallery == 1)
            {
                if (Preloader.Contains(Pics[id]))
                {
                    PreviewItemClick(Preloader.Load(Pics[id]), id);
                }
                else
                {
                    var z = GetPicGallery.Container.Children[id] as UserControls.PicGalleryItem;
                    PreviewItemClick(z.img.Source, id);
                }

                if (WindowLogic.AutoFitWindow)
                {
                    GetPicGallery.Width  = xWidth;
                    GetPicGallery.Height = xHeight;
                }

                GetPicGallery.x2.Visibility = Visibility.Hidden;

                LoadWindows.GetMainWindow.MainImage.Source = null;

                var img = new Image()
                {
                    Source              = GetThumb(id),
                    Stretch             = Stretch.Fill,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center
                };

                // Need to add border for background to pictures with transparent background
                var border = new Border()
                {
                    Background = ConfigureSettings.ConfigColors.GetBackgroundColorBrush()
                };
                border.Child = img;
                GetPicGallery.grid.Children.Add(border);

                var from         = picGalleryItem_Size;
                var to           = new double[] { xWidth, xHeight };
                var acceleration = 0.2;
                var deceleration = 0.4;
                var duration     = TimeSpan.FromSeconds(.3);

                AnimationHelper.Fade(GetPicGallery.Container, duration, TimeSpan.Zero, 1, 0);

                var da = new DoubleAnimation
                {
                    From              = 0,
                    To                = to[0],
                    Duration          = duration,
                    AccelerationRatio = acceleration,
                    DecelerationRatio = deceleration,
                    FillBehavior      = FillBehavior.Stop
                };

                var da0 = new DoubleAnimation
                {
                    From              = 0,
                    To                = to[1],
                    Duration          = duration,
                    AccelerationRatio = acceleration,
                    DecelerationRatio = deceleration,
                    FillBehavior      = FillBehavior.Stop
                };

                da.Completed += delegate
                {
                    ItemClick(id);
                    GetPicGallery.grid.Children.Remove(border);
                    img    = null;
                    IsOpen = false;
                };

                border.BeginAnimation(FrameworkElement.WidthProperty, da);
                border.BeginAnimation(FrameworkElement.HeightProperty, da0);
            }
            else
            {
                ItemClick(id);
            }
        }
Exemplo n.º 7
0
        internal static string[] RetrieveData(string file)
        {
            var fileInfo = new FileInfo(file);
            var image    = Preloader.Load(Navigation.Pics[Navigation.FolderIndex]);

            var inchesWidth  = image.PixelWidth / image.DpiX;
            var inchesHeight = image.PixelHeight / image.DpiY;
            var cmWidth      = inchesWidth * 2.54;
            var cmHeight     = inchesHeight * 2.54;

            var    firstRatio  = image.PixelWidth / Utilities.GCD(image.PixelWidth, image.PixelHeight);
            var    secondRatio = image.PixelHeight / Utilities.GCD(image.PixelWidth, image.PixelHeight);
            string ratioText;

            if (firstRatio == secondRatio)
            {
                ratioText = $"{firstRatio}:{secondRatio} ({Application.Current.Resources["Square"]})";
            }
            else if (firstRatio > secondRatio)
            {
                ratioText = $"{firstRatio}:{secondRatio} ({Application.Current.Resources["Landscape"]})";
            }
            else
            {
                ratioText = $"{firstRatio}:{secondRatio} ({Application.Current.Resources["Portrait"]})";
            }

            var so       = ShellObject.FromParsingName(file);
            var bitdepth = so.Properties.GetProperty(SystemProperties.System.Image.BitDepth).ValueAsObject;
            var dpiX     = so.Properties.GetProperty(SystemProperties.System.Image.HorizontalResolution).ValueAsObject;
            var dpiY     = so.Properties.GetProperty(SystemProperties.System.Image.VerticalResolution).ValueAsObject;

            so.Dispose();

            return(new string[]
            {
                // Fileinfo
                fileInfo.Name,
                fileInfo.DirectoryName,
                fileInfo.FullName,
                fileInfo.CreationTime.ToString(CultureInfo.CurrentCulture),
                fileInfo.LastWriteTime.ToString(CultureInfo.CurrentCulture),

                // Resolution
                image.PixelWidth + " x " + image.PixelHeight + " " + Application.Current.Resources["Pixels"],

                // DPI
                Math.Round((double)dpiX) + " x " + Math.Round((double)dpiY) + " " + Application.Current.Resources["Dpi"],

                // Bit dpeth
                bitdepth.ToString(),

                // Megapixels
                ((float)image.PixelHeight * image.PixelWidth / 1000000)
                .ToString("0.##", CultureInfo.CurrentCulture) + " " + Application.Current.Resources["MegaPixels"],

                // Print size cm
                cmWidth.ToString("0.##", CultureInfo.CurrentCulture) + " x " + cmHeight.ToString("0.##", CultureInfo.CurrentCulture)
                + " " + Application.Current.Resources["Centimeters"],

                // Print size inch
                inchesWidth.ToString("0.##", CultureInfo.CurrentCulture) + " x " + inchesHeight.ToString("0.##", CultureInfo.CurrentCulture)
                + " " + Application.Current.Resources["Inches"],

                // Aspect ratio
                ratioText
            });
        }
Exemplo n.º 8
0
        /// <summary>
        /// Loads image based on overloaded int.
        /// </summary>
        /// <param name="x">The index of file to load from Pics</param>
        internal static async void Pic(int x)
        {
            BitmapSource pic;

            // Additional error checking
            if (Pics.Count <= x)
            {
                if (x == 0)
                {
                    var recovery = await RecoverFailedArchiveAsync().ConfigureAwait(true);

                    if (!recovery)
                    {
                        ToolTipStyle("Archive could not be processed");
                        Reload(true);
                        return;
                    }
                }

                // Untested code
                pic = await PicErrorFix(x).ConfigureAwait(true);

                if (pic == null)
                {
                    Reload(true);
                    return;
                }
            }
            if (x < 0)
            {
                pic = await PicErrorFix(x).ConfigureAwait(true);
            }
            //if (!canNavigate)
            //{
            //    Reload(true);
            //    return;
            //}
            else
            {
                /// Add "pic" as local variable used for the image.
                /// Use the Load() function load image from memory if available
                /// if not, it will be null
                pic = Preloader.Load(Pics[x]);
            }


            if (pic == null)
            {
                mainWindow.Title       = Loading;
                mainWindow.Bar.Text    = Loading;
                mainWindow.Bar.ToolTip = Loading;

                TryZoomFit(Pics[x]);

                var thumb = GetThumb();

                if (thumb != null)
                {
                    mainWindow.img.Source = thumb;
                }

                // Dissallow changing image while loading
                canNavigate = false;

                if (freshStartup)
                {
                    // Load new value manually
                    await Task.Run(() => pic = RenderToBitmapSource(Pics[x])).ConfigureAwait(true);
                }
                else
                {
                    do
                    {
                        // Try again while loading?
                        await Task.Delay(20).ConfigureAwait(true);

                        if (x < Pics.Count)
                        {
                            pic = Preloader.Load(Pics[x]);
                        }
                    } while (Preloader.IsLoading);
                }

                // If pic is still null, image can't be rendered
                if (pic == null)
                {
                    // Attempt to load new image
                    pic = await PicErrorFix(x).ConfigureAwait(true);

                    if (pic == null)
                    {
                        if (Pics.Count <= 1)
                        {
                            Unload();
                            return;
                        }

                        DisplayBrokenImage();
                        canNavigate = true;
                        return;
                    }
                }
            }

            // Clear unsupported image window, if shown
            if (mainWindow.img.Source == null && !freshStartup)
            {
                if (mainWindow.topLayer.Children.Count > 0)
                {
                    mainWindow.topLayer.Children.Clear();
                }
            }

            // Show the image! :)
            mainWindow.img.Source = pic;

            ZoomFit(pic.PixelWidth, pic.PixelHeight);

            // Scroll to top if scroll enabled
            if (IsScrollEnabled)
            {
                mainWindow.Scroller.ScrollToTop();
            }

            /// TODO Make it staying flipped a user preference
            //// Prevent picture from being flipped if previous is
            //if (Flipped)
            //    Flip();

            // Update values
            canNavigate = true;
            SetTitleString(pic.PixelWidth, pic.PixelHeight, x);
            FolderIndex = x;
            AjaxLoadingEnd();

            if (Pics.Count > 0)
            {
                Progress(x, Pics.Count);

                // Preload images \\
                if (Preloader.StartPreload())
                {
                    Preloader.Add(pic, Pics[FolderIndex]);
                    await Preloader.PreLoad(x).ConfigureAwait(false);
                }
            }

            if (!freshStartup)
            {
                RecentFiles.Add(Pics[x]);
            }

            freshStartup = false;
        }
Exemplo n.º 9
0
        internal static string[] RetrieveData(string file)
        {
            string name, directoryname, fullname, creationtime, lastwritetime;

            FileInfo fileInfo;

            try
            {
                fileInfo      = new FileInfo(file);
                name          = fileInfo.Name;
                directoryname = fileInfo.DirectoryName;
                fullname      = fileInfo.FullName;
                creationtime  = fileInfo.CreationTime.ToString(CultureInfo.CurrentCulture);
                lastwritetime = fileInfo.LastWriteTime.ToString(CultureInfo.CurrentCulture);
            }
            catch (Exception)
            {
                name          = string.Empty;
                directoryname = string.Empty;
                fullname      = string.Empty;
                creationtime  = string.Empty;
                lastwritetime = string.Empty;
            }

            var image = Preloader.Load(Navigation.Pics[Navigation.FolderIndex]);

            var inchesWidth  = image.PixelWidth / image.DpiX;
            var inchesHeight = image.PixelHeight / image.DpiY;
            var cmWidth      = inchesWidth * 2.54;
            var cmHeight     = inchesHeight * 2.54;

            var    firstRatio  = image.PixelWidth / UILogic.TransformImage.ZoomLogic.GCD(image.PixelWidth, image.PixelHeight);
            var    secondRatio = image.PixelHeight / UILogic.TransformImage.ZoomLogic.GCD(image.PixelWidth, image.PixelHeight);
            string ratioText;

            if (firstRatio == secondRatio)
            {
                ratioText = $"{firstRatio}:{secondRatio} ({Application.Current.Resources["Square"]})";
            }
            else if (firstRatio > secondRatio)
            {
                ratioText = $"{firstRatio}:{secondRatio} ({Application.Current.Resources["Landscape"]})";
            }
            else
            {
                ratioText = $"{firstRatio}:{secondRatio} ({Application.Current.Resources["Portrait"]})";
            }

            object bitdepth, dpiX, dpiY;
            string dpi;

            try
            {
                var so = ShellObject.FromParsingName(file);
                bitdepth = so.Properties.GetProperty(SystemProperties.System.Image.BitDepth).ValueAsObject;
                dpiX     = so.Properties.GetProperty(SystemProperties.System.Image.HorizontalResolution).ValueAsObject;
                dpiY     = so.Properties.GetProperty(SystemProperties.System.Image.VerticalResolution).ValueAsObject;
                so.Dispose();
            }
            catch (Exception)
            {
                bitdepth = string.Empty;
                dpiX     = string.Empty;
                dpiY     = string.Empty;
            }

            if (bitdepth == null)
            {
                bitdepth = string.Empty;
            }

            if (dpiX == null)
            {
                dpi = string.Empty;
            }
            else
            {
                dpi = Math.Round((double)dpiX) + " x " + Math.Round((double)dpiY) + " " + Application.Current.Resources["Dpi"];
            }

            return(new string[]
            {
                // Fileinfo
                name,
                directoryname,
                fullname,
                creationtime,
                lastwritetime,

                // Resolution
                image.PixelWidth + " x " + image.PixelHeight + " " + Application.Current.Resources["Pixels"],

                // DPI
                dpi,

                // Bit dpeth
                bitdepth.ToString(),

                // Megapixels
                ((float)image.PixelHeight * image.PixelWidth / 1000000)
                .ToString("0.##", CultureInfo.CurrentCulture) + " " + Application.Current.Resources["MegaPixels"],

                // Print size cm
                cmWidth.ToString("0.##", CultureInfo.CurrentCulture) + " x " + cmHeight.ToString("0.##", CultureInfo.CurrentCulture)
                + " " + Application.Current.Resources["Centimeters"],

                // Print size inch
                inchesWidth.ToString("0.##", CultureInfo.CurrentCulture) + " x " + inchesHeight.ToString("0.##", CultureInfo.CurrentCulture)
                + " " + Application.Current.Resources["Inches"],

                // Aspect ratio
                ratioText
            });
        }
Exemplo n.º 10
0
        internal static Size?ImageSize(string file, bool usePreloader = false, bool advancedFormats = false)
        {
            if (usePreloader)
            {
                var pic = Preloader.Load(Pics[FolderIndex]);
                if (pic != null)
                {
                    return(new Size(pic.PixelWidth, pic.PixelHeight));
                }
            }

            using var magick = new MagickImage();
            var ext = Path.GetExtension(file).ToUpperInvariant();

            switch (ext)
            {
            // Standards
            case ".JPG":
            case ".JPEG":
            case ".JPE":
            case ".JFIF":
                magick.Format = MagickFormat.Jpg;
                break;

            case ".PNG":
                magick.Format = MagickFormat.Png;
                break;

            case ".BMP":
                magick.Format = MagickFormat.Bmp;
                break;

            case ".TIF":
            case ".TIFF":
                magick.Format = MagickFormat.Tif;
                break;

            case ".GIF":
                magick.Format = MagickFormat.Gif;
                break;

            case ".ICO":
                magick.Format = MagickFormat.Ico;
                break;

            default:
                if (!advancedFormats)
                {
                    // don't read advanced formats
                    return(null);
                }

                break;
            }

            try
            {
                magick.Read(file);
            }
#if DEBUG
            catch (MagickException e)
            {
                Trace.WriteLine("ImageSize returned " + file + " null, \n" + e.Message);
                return(null);
            }
#else
            catch (MagickException) { return(null); }
#endif

            return(new Size(magick.Width, magick.Height));
        }