public void LoadImage(IBitmap image, string fileName) { bitmap = image; TabModel.ToolTip = fileName; TabModel.Header = Utils.GetFileName(fileName); sourceName = Utils.GetFileNameWithoutExtension(fileName); Indexes = Enumerable.Range(0, bitmap.SubmapCount); dds = bitmap.ToDds(0); Render(); CoerceValue(HasMultipleProperty); }
private void ExportImage(bool allChannels) { var filter = "TIF Files|*.tif|PNG Files|*.png|JPEG Files|*.jpeg|TARGA Files|*.tga"; if (allChannels) { filter += "|DDS Files|*.dds"; } var sfd = new SaveFileDialog { OverwritePrompt = true, FileName = sourceName, Filter = filter, FilterIndex = 1, AddExtension = true }; if (sfd.ShowDialog() != true) { return; } var dir = Directory.GetParent(sfd.FileName).FullName; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } if (sfd.FilterIndex == 4) { var source = allChannels ? dds.ToBitmapSource() : ImageSource; source.WriteToTarga(sfd.FileName, System.Drawing.Imaging.PixelFormat.Format32bppArgb); return; } else if (sfd.FilterIndex == 5) { var dds = bitmap.ToDds(0); dds.WriteToDxgi(sfd.FileName); return; } using (var fs = new FileStream(sfd.FileName, FileMode.Create)) { BitmapEncoder encoder; switch (sfd.FilterIndex) { case 1: encoder = new TiffBitmapEncoder(); break; case 2: encoder = new PngBitmapEncoder(); break; case 3: encoder = new JpegBitmapEncoder(); break; default: throw new InvalidOperationException(); } var src = allChannels ? dds.ToBitmapSource() : ImageSource; encoder.Frames.Add(BitmapFrame.Create(src)); encoder.Save(fs); } }
private bool SaveImage(IBitmap bitmap, string baseDir) { var extracted = 0; for (int i = 0; i < bitmap.SubmapCount; i++) { var fileName = MakePath(bitmap.Class, bitmap.Name, baseDir); var ext = "." + Settings.BitmapFormat.ToString().ToLower(); if (bitmap.SubmapCount > 1) { fileName += $"[{i}]"; } if (Settings.BitmapFormat == BitmapFormat.DDS) { if (Settings.OverwriteExisting || !File.Exists(fileName + ext)) { var rawDds = bitmap.ToDds(i); rawDds.WriteToDxgi(fileName + ext); extracted++; } continue; } var outputs = new List <Tuple <string, DecompressOptions> >(); ImageFormat format; if (Settings.BitmapFormat == BitmapFormat.PNG) { format = ImageFormat.Png; } else if (Settings.BitmapFormat == BitmapFormat.TIF) { format = ImageFormat.Tiff; } else if (Settings.BitmapFormat == BitmapFormat.JPEG) { format = ImageFormat.Jpeg; } else //if (Settings.BitmapFormat == BitmapFormat.TGA) { format = null; } if (Settings.BitmapMode == BitmapMode.Default) { outputs.Add(Tuple.Create(fileName + ext, DecompressOptions.Default)); } else if (Settings.BitmapMode == BitmapMode.Bgr24) { outputs.Add(Tuple.Create(fileName + ext, DecompressOptions.Bgr24)); } else if (Settings.BitmapMode == BitmapMode.IsolateAlpha) { outputs.AddRange(GetParamsIsolateAlpha(fileName, ext)); } else if (Settings.BitmapMode == BitmapMode.IsolateAll) { outputs.AddRange(GetParamsIsolateAll(fileName, ext)); } else if (Settings.BitmapMode == BitmapMode.MixedIsolate) { outputs.AddRange(GetParamsMixedIsolate(fileName, ext)); } DdsImage dds = null; foreach (var param in outputs) { if (!Settings.OverwriteExisting && File.Exists(param.Item1)) { continue; } if (dds == null) { dds = bitmap.ToDds(i); } var args = new DdsOutputArgs(param.Item2, bitmap.CubeLayout); if (format != null) { dds.WriteToDisk(param.Item1, format, args); } else //if (Settings.BitmapFormat == BitmapFormat.TGA) { dds.WriteToTarga(param.Item1, args); } extracted++; } } return(extracted > 0); }