private void SetImagePreview(BlitzGraphic graphic) { SelectedGraphic = graphic; Bitmap image = graphic.BlitzImage; imagePreviewPanel.Visibility = Visibility.Visible; if (image != null) { using (MemoryStream memory = new MemoryStream()) { image.Save(memory, ImageFormat.Png); memory.Position = 0; BitmapImage bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = memory; bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.EndInit(); previewImage.Source = bitmapImage; } } else { previewImage.Source = null; } cbImageType.SelectedValue = (N64ImageType)Enum.Parse(typeof(N64ImageType), graphic.ImageType); tbIRX.Text = graphic.IRX.ToString(); tbIRY.Text = graphic.IRY.ToString(); }
private void btnLoadReplacementFile_Click(object sender, RoutedEventArgs e) { OpenFileDialog openDialog = new OpenFileDialog(); Nullable <bool> result = openDialog.ShowDialog(); if (result == true) { byte[] replacementFile; if (openDialog.FileName.ToLower().Contains(".png") || openDialog.FileName.ToLower().Contains(".bmp")) { ImageCoder imageCoder = new ImageCoder(); imageCoder.Convert(new Bitmap(openDialog.FileName)); List <byte> convertedImage = new List <byte>(); // testing out using part of existing header TODO BlitzGameFile selectedGame = (BlitzGameFile)lbGameFiles.SelectedItem; BlitzGraphic currentGraphic = GetBlitzGraphic(selectedGame); convertedImage.AddRange(Blitz2000Header.CreateNFLBlitz2000Header(imageCoder.Width, imageCoder.Height, imageCoder.HasAlpha, (byte)imageCoder.n64ImageType, currentGraphic.IRX, currentGraphic.IRY)); convertedImage.AddRange(imageCoder.Data); if (imageCoder.Palette != null) { convertedImage.AddRange(imageCoder.Palette); } replacementFile = convertedImage.ToArray(); openDialog.FileName = openDialog.FileName.Split('.')[0] + ".wms"; File.WriteAllBytes(openDialog.FileName, convertedImage.ToArray()); } replacementFile = File.ReadAllBytes(openDialog.FileName); InsertReplacementFile(replacementFile); } }
/// <summary> /// When a user chnages the selected n64 graphics type, we convert it to that type. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cbImageType_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (lbGameFiles.SelectedValue == null) { return; } BlitzGraphic currentGraphic = GetBlitzGraphic((BlitzGameFile)lbGameFiles.SelectedItem); if (cbImageType.IsDropDownOpen && (N64ImageType)Enum.Parse(typeof(N64ImageType), currentGraphic.ImageType) != (N64ImageType)cbImageType.SelectedValue) { ImageCoder imageCoder = new ImageCoder(); imageCoder.ConvertTo(currentGraphic.BlitzImage, (N64ImageType)cbImageType.SelectedValue); List <byte> convertedImage = new List <byte>(); convertedImage.AddRange(Blitz2000Header.CreateNFLBlitz2000Header(imageCoder.Width, imageCoder.Height, imageCoder.HasAlpha, (byte)imageCoder.n64ImageType, currentGraphic.IRX, currentGraphic.IRY)); convertedImage.AddRange(imageCoder.Data); InsertReplacementFile(convertedImage.ToArray()); } }