private static void SaveAsPng(string gpFile, string pngDirectory) { IRenderer renderer = new BitmapRenderer(); var imagePaletteBytes = new Extractor().GetPaletteBytes(gpFile); var extractResult = new Extractor().GetImagesFromOutput(gpFile).ToList(); var rawParser = new RawParser(); var paletteBytes = File.ReadAllBytes(@"..\..\..\..\palette\0\agew_1.pal"); var colorCollection = rawParser.GetColorCollectionFromPalleteFile(paletteBytes); var imagePaletteColors = ImageGenerator.OffsetsToColors(imagePaletteBytes, colorCollection); var nationColorOffset = NationColorOffset.Red; using (var bitMap = new Runner().Run(extractResult, nationColorOffset, 0, rawParser, renderer, imagePaletteColors, colorCollection)) { using (var stream = new MemoryStream()) { bitMap.Save(stream, ImageFormat.Png); File.WriteAllBytes(Path.Combine(pngDirectory, Path.GetFileNameWithoutExtension(gpFile) + ".png"), stream.ToArray()); } } }
private IList<Bitmap> DrawImage(IList<ImageLayout> extractResult, NationColorOffset nationColorOffset, int numberOfImages, RawParser rawParser, IRenderer renderer, Color[] imagePaletteArray, Color[] generalPalleteArray) { return Helper.WithMeasurement( () => { var bitMapCollection = new Collection<Bitmap>(); //var idsForProcessing = new[] { 0 }; var idsForProcessing = Enumerable.Range(1, numberOfImages - 1).ToList(); foreach (var imageNumber in idsForProcessing) { Debug.WriteLine("***************************** " + imageNumber); Watch(extractResult[imageNumber].PartialLayouts.ToList()); } foreach (int i in idsForProcessing) { Helper.WithMeasurement(() => { try { var bitMap = new Runner().Run(extractResult, nationColorOffset, i, rawParser, renderer, imagePaletteArray, generalPalleteArray); bitMapCollection.Add(bitMap); } catch (Exception ex) { } }, "Image", onFinish: elapsed => richTextBox1.Text += String.Format("[{0,4}] - {1:g}\n", i, elapsed)); } return bitMapCollection; }, name: "Run", onFinish: elapsed => richTextBox1.Text += String.Format("Finished in {0:c}\n ", elapsed)); }