public static BitmapImage TgaToBitmap(TGA tga) { try { using (var tgaBitmap = tga.ToBitmap()) { using (var memory = new MemoryStream()) { tgaBitmap.Save(memory, ImageFormat.Png); memory.Position = 0; var bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = memory; bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.EndInit(); bitmapImage.Freeze(); return(bitmapImage); } } } catch (Exception e) { logger.Error(e, $"Failed to create bitmap from TGA image."); return(null); } }
public void extractFiles(string archievedFile, string relativePath, string OutputPath, int scaling) { foreach (ZipArchiveEntry entry in zipfile.Entries) { if (entry.FullName.StartsWith(archievedFile)) { string path = OutputPath + entry.FullName.Replace(relativePath, ""); Directory.CreateDirectory(Path.GetDirectoryName(path)); entry.ExtractToFile(path, true); if (Path.GetExtension(path).Contains("tga")) { bool skip = false; foreach (string excludePath in excludeResizePaths) { if (path.Contains(excludePath)) { skip = true; } } if (!skip) { int multiplier = scaling; TGA image = new TGA(path); ImageScaler scaler = new ImageScalerImpl(); scaler.ResizeImage(image.ToBitmap(), image.Width * multiplier, image.Height * multiplier, path); } } } } }
public static BitmapImage TgaToBitmap(TGA tga) { var tgaBitmap = tga.ToBitmap(); using (var memory = new MemoryStream()) { tgaBitmap.Save(memory, ImageFormat.Png); memory.Position = 0; var bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = memory; bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.EndInit(); bitmapImage.Freeze(); return(bitmapImage); } }