示例#1
0
        /// <summary>
        /// Opens a dialog for the user to add images as frames.
        /// </summary>
        /// <param name="spriteSheet">
        /// The sprite sheet to add files to if the user successfully adds images.
        /// </param>
        private void AddFiles(SpriteSheet spriteSheet)
        {
            OpenFileDialog dlg = new OpenFileDialog
            {
                CheckPathExists = true,
                DefaultExt      = ".png",
                Filter          = "png files|*.png",
                Multiselect     = true
            };

            try
            {
                if (dlg.ShowDialog() == true)
                {
                    foreach (string fname in dlg.FileNames)
                    {
                        string      file     = System.IO.Path.GetFileNameWithoutExtension(fname);
                        Model.Frame newFrame = new Model.Frame($"{file}");
                        newFrame.SetRelativePath(new Uri(fname), new Uri(projectSaveUrl));
                        spriteSheet.Frames.Add(newFrame);
                    }

                    SetWorkUnsavedIndicator(true);
                }
            }
            catch
            {
                MessageBox.Show(
                    "One or more of the indicated files could not be loaded.",
                    "Add files failed",
                    MessageBoxButton.OK,
                    MessageBoxImage.Error);
            }
        }
示例#2
0
        /// <summary>
        /// Attempts to read the width and height metadata of all frames in the spritesheet, and
        /// updates the associated frames' width and height dimensions.
        /// </summary>
        /// <exception cref="ArgumentException"/>
        /// <exception cref="ArgumentNullException"/>
        /// <exception cref="PathTooLongException"/>
        /// <exception cref="DirectoryNotFoundException"/>
        /// <exception cref="UnauthorizedAccessException"/>
        /// <exception cref="FileNotFoundException"/>
        /// <exception cref="NotSupportedException"/>
        /// <exception cref="IOException"/>
        private void RefreshImageDimensions(SpriteSheet spriteSheet)
        {
            for (int i = 0; i < spriteSheet.Frames.Count; i++)
            {
                Model.Frame frame = spriteSheet.Frames[i];

                using (FileStream imageStream = File.OpenRead(frame.GetAbsolutePath(projectSaveUrl)))
                {
                    BitmapDecoder decoder = BitmapDecoder.Create(
                        imageStream,
                        BitmapCreateOptions.IgnoreColorProfile,
                        BitmapCacheOption.Default);

                    frame.W = decoder.Frames[0].PixelWidth;
                    frame.H = decoder.Frames[0].PixelHeight;
                }
            }
        }