public void LoadICO(string path) { byte[] data = File.ReadAllBytes(path); ico = new ICOFile(data); icoLoadedPath = path; RefreshAll(); }
static void CreateFromImage(string imagePath, string outputPath, ICOImageType imageType) { ICOFile ico = new ICOFile(ICOType.ICO); ico.Images.Add(ICOImage.ReadFromFile(imagePath)); ico.Images[0].Type = imageType; ico.WriteToFile(outputPath); }
static void DumpInfo(string path) { ICOFile ico = ICOFile.ReadFromFile(path, false); foreach (ICOImage img in ico.Images) { Console.WriteLine(string.Format("{0}: {1}x{2}", Enum.GetName(typeof(ICOImageType), img.Type), img.Width, img.Height)); } }
static void ExportFromICO(string ICOPath, string outpath) { DirectoryInfo di = new DirectoryInfo(outpath); if (!di.Exists) { di.Create(); } ICOFile ico = ICOFile.ReadFromFile(ICOPath, false); for (int i = 0; i < ico.Images.Count; i++) { ICOImage img = ico.Images[i]; img.Image.Save(Path.Combine(di.FullName, string.Format("Image{0}.png", i)), ImageFormat.Png); } }
public void NewICO(ICOType type) { ico = new ICOFile(type); icoLoadedPath = null; RefreshAll(); }
private void displayFileDetails(DATFileEntry entry) { Text = baseTitle + " - " + entry.Filename; savePNGButton.Visible = false; savePNGSButton.Visible = false; currentExportBitmap = null; currentExportBitmaps = null; switch (entry.Type) { case "MAP": MAPFile map = new MAPFile(entry); if (map.Error != "") { MessageBox.Show(map.Error, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Palette palette = Palette.Default; Bitmap mapBitmap = null; // find matching ICO tileset and PCC for palette if (entry.Filename.StartsWith("W")) { string baseName = entry.Filename.Substring(0, 2); if (container.Entries.ContainsKey(baseName + ".ICO")) { palette = getPaletteFrom(baseName + ".PCC"); if (palette == null) { palette = Palette.Default; } else if (baseName != "W2") { addW2Palette(palette); } ICOFile icoFile = new ICOFile(container.Entries[baseName + ".ICO"], palette); int scale = 1; mapBitmap = MAPPainter.Paint(map, icoFile, scale); currentExportBitmap = scale == 1 ? mapBitmap : MAPPainter.Paint(map, icoFile, 1); } } imgPictureBox.Image = mapBitmap; setPaletteImage(palette); log($"MAP loaded: name={entry.Filename}, width={map.Width}, height={map.Height}, palette={palette.Name}"); break; case "ARE": AREFile area = new AREFile(entry); if (area.Error != "") { MessageBox.Show(area.Error, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //imgPictureBox.Image = BitmapScaler.PixelScale(, 3); //palettePictureBox.Image = BitmapScaler.PixelScale(Palette.ToBitmap(Palette.Default), 6); break; case "BOB": string name = Path.GetFileNameWithoutExtension(entry.Filename); if (container.Entries.ContainsKey(name + ".PCC")) { palette = getPaletteFrom(name + ".PCC"); } else if (name.Length == 1) { palette = getPaletteFrom("ANTS.PCC"); // the ants have names like A.BOB to O.BOB } else { palette = getPaletteFrom("W2.PCC"); palette.Colors[0] = Color.Black; palette.Name += " (mod)"; } BOBFile b = new BOBFile(entry, palette); if (b.Error != "") { MessageBox.Show(b.Error, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } log($"BOB contains {b.Elements.Count} images"); currentExportBitmaps = b.Elements.ToArray(); currentExportBitmap = BOBPainter.MakeSheet(b); imgPictureBox.Image = BitmapScaler.PixelScale(currentExportBitmap, 3); setPaletteImage(palette); break; case "ICO": // tileset / spritesheet string world = entry.Filename.Contains("W1") ? "W1" : (entry.Filename.Contains("W2") ? "W2" : "W3"); palette = getPaletteFrom(world + ".PCC"); if (palette == null) { palette = Palette.Default; } else if (world != "W2") { addW2Palette(palette); } ICOFile ico = new ICOFile(entry, palette); if (ico.Error != "") { MessageBox.Show("Failed to load ICO, sorry!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } log($"ICO contains {ico.Bitmaps.Length} tiles"); currentExportBitmaps = ico.Bitmaps; currentExportBitmap = ICOPainter.TileSetFromBitmaps(ico.Bitmaps); imgPictureBox.Image = BitmapScaler.PixelScale(currentExportBitmap, 3); setPaletteImage(palette); break; case "PCC": // these are actually PCX files, version 5, encoded, 8 bits per pixel PCXFile pcx = new PCXFile(); if (!pcx.Load(entry.Data)) { MessageBox.Show(pcx.Error, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } currentExportBitmap = pcx.Bitmap; imgPictureBox.Image = BitmapScaler.PixelScale(pcx.Bitmap, 4); setPaletteImage(Palette.ToBitmap(pcx.Palette), "own"); log($"PCC loaded: name={entry.Filename}, width={pcx.Bitmap.Width}, height={pcx.Bitmap.Height}, palette=own"); break; default: break; } if (currentExportBitmap != null) { savePNGButton.Visible = true; } if (currentExportBitmaps != null && currentExportBitmaps.Length > 0) { savePNGSButton.Visible = true; } }