/// <summary> /// Not generic enough to call with custom derived classes other than /// MapFileChild. /// </summary> /// <param name="fullpath"></param> public void Screenshot(string fullpath) { var pal = Descriptor.Pal; // var pal = GetFirstGroundPalette(); // if (pal == null) // throw new ArgumentNullException("fullpath", "MapFileBase: At least 1 ground tile is required."); // TODO: I don't want to see 'ArgumentNullException'. Just say // what's wrong and save the technical details for the debugger. var width = MapSize.Rows + MapSize.Cols; var b = BitmapService.CreateTransparent( width * (XCImage.SpriteWidth / 2), (MapSize.Levs - Level) * 24 + width * 8, pal.ColorTable); var start = new Point( (MapSize.Rows - 1) * (XCImage.SpriteWidth / 2), -(24 * Level)); int i = 0; if (MapTiles != null) { for (int lev = MapSize.Levs - 1; lev >= Level; --lev) { for (int row = 0, startX = start.X, startY = start.Y + lev * 24; row != MapSize.Rows; ++row, startX -= HalfWidthConst, startY += HalfHeightConst) { for (int col = 0, x = startX, y = startY; col != MapSize.Cols; ++col, x += HalfWidthConst, y += HalfHeightConst, ++i) { var parts = this[row, col, lev].UsedParts; foreach (var part in parts) { var tilepart = part as Tilepart; BitmapService.Draw( // NOTE: not actually drawing anything. tilepart[0].Sprite, b, x, y - tilepart.Record.TileOffset); } } } } } try { var rect = BitmapService.GetNontransparentRectangle(b, Palette.TransparentId); b = BitmapService.Crop(b, rect); b.Save(fullpath, ImageFormat.Png); } catch // TODO: Deal with exceptions appropriately. { b.Save(fullpath, ImageFormat.Png); throw; } if (b != null) { b.Dispose(); } }
/// <summary> /// Not generic enough to call with custom derived classes other than /// MapFileChild. /// </summary> /// <param name="fullpath"></param> public void SaveGifFile(string fullpath) { var palette = GetFirstGroundPalette(); if (palette == null) { throw new ArgumentNullException("fullpath", "MapFileBase: At least 1 ground tile is required."); } // TODO: I don't want to see 'ArgumentNullException'. Just say // what's wrong and save the technical details for the debugger. var rowcols = MapSize.Rows + MapSize.Cols; var bitmap = BitmapService.MakeBitmap( rowcols * (XCImage.SpriteWidth / 2), (MapSize.Levs - Level) * 24 + rowcols * 8, palette.ColorTable); var start = new Point( (MapSize.Rows - 1) * (XCImage.SpriteWidth / 2), -(24 * Level)); int i = 0; if (MapTiles != null) { for (int lev = MapSize.Levs - 1; lev >= Level; --lev) { for (int row = 0, startX = start.X, startY = start.Y + lev * 24; row != MapSize.Rows; ++row, startX -= HalfWidthConst, startY += HalfHeightConst) { for (int col = 0, x = startX, y = startY; col != MapSize.Cols; ++col, x += HalfWidthConst, y += HalfHeightConst, ++i) { var usedParts = this[row, col, lev].UsedTiles; foreach (var usedPart in usedParts) { var part = usedPart as Tilepart; BitmapService.Draw( // NOTE: not actually drawing anything. part[0].Image, bitmap, x, y - part.Record.TileOffset); } // XCBitmap.UpdateProgressBar(i, (MapSize.Levs - Level) * MapSize.Rows * MapSize.Cols); } } } } try { var rect = BitmapService.GetNontransparentRectangle(bitmap, Palette.TransparentId); bitmap = BitmapService.Crop(bitmap, rect); bitmap.Save(fullpath, ImageFormat.Gif); } catch { bitmap.Save(fullpath, ImageFormat.Gif); throw; } }