Ejemplo n.º 1
0
        /// <summary>
        /// Sets the controls properties to the values in the given command.
        /// </summary>
        /// <param name="command">The command, if null is passed, the UI is cleared.</param>
        private void ShowCommandDetails(Command command)
        {
            if (command == null)
            {
                tbName.Text          = "";
                iIcon.Source         = null;
                tbNoImage.Visibility = Visibility.Hidden;
                return;
            }

            tbName.Text = command.Name;
            MadCatzProfile profile = presenter.ActiveProfile;
            Blast          blast   = profile.Blasts.GetBlastForCommand(command);

            if (blast != null)
            {
                iIcon.Source         = ImageHelper.CreateImage(blast.GetData());
                tbNoImage.Visibility = Visibility.Hidden;
                iIcon.Visibility     = Visibility.Visible;
            }
            else
            {
                tbNoImage.Visibility = Visibility.Visible;
                iIcon.Visibility     = Visibility.Hidden;
            }
        }
Ejemplo n.º 2
0
        public void ExtractIconRequested(Blast blast)
        {
            if (blast == null)
            {
                throw new ArgumentNullException("blast");
            }

            FileInfo saveFile = view.SelectImageSaveFile();

            if (saveFile == null)
            {
                return;
            }

            switch (saveFile.Extension.ToUpperInvariant())
            {
            case ".BMP":
                SaveToFile(saveFile, blast, new BmpBitmapEncoder());
                break;

            case ".GIF":
                SaveToFile(saveFile, blast, new GifBitmapEncoder());
                break;

            case ".JPEG":
            case ".JPG":
                SaveToFile(saveFile, blast, new JpegBitmapEncoder());
                break;

            case ".PNG":
                SaveToFile(saveFile, blast.GetData());
                break;

            case ".TIF":
            case ".TIFF":
                SaveToFile(saveFile, blast, new TiffBitmapEncoder());
                break;

            default:
                mainPresenter.ForwardError((string)Application.Current.FindResource(ERROR_MESSAGE_INVALID_IMAGE_FORMAT));
                break;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Saves the icon using the given encoder to the given file.
        /// </summary>
        /// <param name="file">File to save to.</param>
        /// <param name="blast">Icon to save.</param>
        /// <param name="encoder">Encoder to use.</param>
        private static void SaveToFile(FileInfo file, Blast blast, BitmapEncoder encoder)
        {
            var image = new BitmapImage();

            using (var stream = new MemoryStream(blast.GetData()))
            {
                image.BeginInit();
                image.CreateOptions = BitmapCreateOptions.PreservePixelFormat;
                image.CacheOption   = BitmapCacheOption.OnLoad;
                image.UriSource     = null;
                image.StreamSource  = stream;
                image.EndInit();
            }
            image.Freeze();

            BitmapFrame frame = BitmapFrame.Create(image);

            encoder.Frames.Add(frame);

            using (FileStream stream = OpenFileStream(file))
            {
                encoder.Save(stream);
            }
        }