예제 #1
0
        protected override void OnMouseEnter(System.Windows.Input.MouseEventArgs e)
        {
            if (!System.IO.File.Exists(this.FullPath) || EditorUtils.isDirectory(this.FullPath))
            {
                return;
            }

            Point p = PointToScreen(e.GetPosition(this));

            lastpos = p;

            if (Text.ToLower().EndsWith(".png") || Text.ToLower().EndsWith(".jpg") ||
                Text.ToLower().EndsWith(".jpeg") || Text.ToLower().EndsWith(".gif") ||
                Text.ToLower().EndsWith(".bmp"))
            {
                EditorHandler.PicturePreview.ChangeImage(FullPath);
                EditorHandler.PicturePreview.Visibility = System.Windows.Visibility.Visible;

                p.Y = Microsoft.Xna.Framework.MathHelper.Clamp(
                    (float)p.Y,
                    0,
                    (float)System.Windows.SystemParameters.WorkArea.Height - (float)EditorHandler.PicturePreview.PreviewImage.Height);

                EditorHandler.PicturePreview.Top  = p.Y - 20;
                EditorHandler.PicturePreview.Left = p.X + 30;
            }
        }
예제 #2
0
        internal void ChangeImage(string path)
        {
            //Dispatcher.Invoke((Action)(() =>
            //{
            //PreviewImage.Source = new BitmapImage(new Uri(path));
            if (lastPath == path || EditorUtils.isDirectory(path))
            {
                return;
            }
            lastPath = path;

            BitmapImage image = new BitmapImage();

            image.BeginInit();
            image.UriSource   = new Uri(path, UriKind.Absolute);
            image.CacheOption = BitmapCacheOption.OnLoad;
            image.EndInit();

            if (image.Width < maxWidth && image.Height < maxHeight)
            {
                PreviewImage.Width  = image.Width;
                PreviewImage.Height = image.Height;
            }
            else
            {
                double ratioX = (double)maxWidth / (double)image.Width;
                double ratioY = (double)maxHeight / (double)image.Height;
                // use whichever multiplier is smaller
                double ratio = ratioX < ratioY ? ratioX : ratioY;

                // now we can get the new height and width
                int newWidth  = Convert.ToInt32(image.Width * ratio);
                int newHeight = Convert.ToInt32(image.Height * ratio);

                PreviewImage.Width  = newWidth;
                PreviewImage.Height = newHeight;
            }

            PreviewImage.Source = image;        //EditorUtils.ConvertBitmapToSource96DPI(image);
            //}));
        }