public static Bitmap CreateBitmap(TmxMap tmxMap, float scale) { SummaryReport report = new SummaryReport(); report.Capture("Previewing"); // What is the boundary of the bitmap we are creating? RectangleF bounds = CalculateBoundary(tmxMap); Bitmap bitmap = null; try { int width = (int)Math.Ceiling(bounds.Width * scale) + 1; int height = (int)Math.Ceiling(bounds.Height * scale) + 1; bitmap = TmxHelper.CreateBitmap32bpp(width, height); } catch (System.ArgumentException) { StringBuilder warning = new StringBuilder(); warning.AppendFormat("Map cannot be previewed at '{0}' scale. Try a smaller scale.\n", scale); warning.AppendLine("Image will be constructed on a 1024x1024 canvas. Parts of your map may be cropped."); Logger.WriteWarning(warning.ToString()); bitmap = TmxHelper.CreateBitmap32bpp(1024, 1024); } using (Pen pen = new Pen(Color.Black, 1.0f)) using (Graphics g = Graphics.FromImage(bitmap)) { g.InterpolationMode = InterpolationMode.NearestNeighbor; #if !TILED2UNITY_MAC g.PixelOffsetMode = PixelOffsetMode.HighQuality; #endif g.ScaleTransform(scale, scale); g.FillRectangle(Brushes.WhiteSmoke, 0, 0, bounds.Width, bounds.Height); g.DrawRectangle(pen, 1, 1, bounds.Width - 1, bounds.Height - 1); g.TranslateTransform(-bounds.X, -bounds.Y); DrawBackground(g, tmxMap); DrawGrid(g, tmxMap, scale); DrawTiles(g, tmxMap); DrawColliders(g, tmxMap, scale); DrawObjectColliders(g, tmxMap); } report.Report(); return(bitmap); }
public static Bitmap CreateBitmap(TmxMap tmxMap, float scale) { SummaryReport report = new SummaryReport(); report.Capture("Previewing"); // What is the boundary of the bitmap we are creating? RectangleF bounds = CalculateBoundary(tmxMap); Bitmap bitmap = null; try { int width = (int)Math.Ceiling(bounds.Width * scale) + 1; int height = (int)Math.Ceiling(bounds.Height * scale) + 1; bitmap = TmxHelper.CreateBitmap32bpp(width, height); } catch (System.ArgumentException) { StringBuilder warning = new StringBuilder(); warning.AppendFormat("Map cannot be previewed at '{0}' scale. Try a smaller scale.\n", scale); warning.AppendLine("Image will be constructed on a 1024x1024 canvas. Parts of your map may be cropped."); Logger.WriteWarning(warning.ToString()); bitmap = TmxHelper.CreateBitmap32bpp(1024, 1024); } using (Pen pen = new Pen(Color.Black, 1.0f)) using (Graphics g = Graphics.FromImage(bitmap)) { g.InterpolationMode = InterpolationMode.NearestNeighbor; #if !TILED2UNITY_MAC g.PixelOffsetMode = PixelOffsetMode.HighQuality; #endif g.ScaleTransform(scale, scale); g.FillRectangle(Brushes.WhiteSmoke, 0, 0, bounds.Width, bounds.Height); g.DrawRectangle(pen, 1, 1, bounds.Width - 1, bounds.Height - 1); g.TranslateTransform(-bounds.X, -bounds.Y); DrawBackground(g, tmxMap); DrawGrid(g, tmxMap); DrawTiles(g, tmxMap); DrawColliders(g, tmxMap, scale); DrawObjectColliders(g, tmxMap); } report.Report(); return bitmap; }
public static SKBitmap CreatePreviewBitmap(TmxMap tmxMap, float scale) { SummaryReport report = new SummaryReport(); report.Capture("Previewing"); // Set our scale to be used throughout the image Scale = scale; // What is the boundary of the bitmap we are creating? SKRect bounds = CalculateBoundary(tmxMap); SKBitmap bitmap = null; try { int width = (int)Math.Ceiling(bounds.Width * scale); int height = (int)Math.Ceiling(bounds.Height * scale); bitmap = new SKBitmap(width, height); } catch { StringBuilder warning = new StringBuilder(); warning.AppendFormat("Map cannot be previewed at '{0}' scale. Try a smaller scale.\n", scale); warning.AppendLine("Image will be constructed on a 2048x2048 canvas. Parts of your map may be cropped."); Logger.WriteWarning(warning.ToString()); bitmap = new SKBitmap(2048, 2048); } using (SKCanvas canvas = new SKCanvas(bitmap)) using (SKPaint paint = new SKPaint()) using (new SKAutoCanvasRestore(canvas)) { // Apply scale then translate canvas.Clear(SKColors.WhiteSmoke); canvas.Scale(scale, scale); canvas.Translate(-bounds.Left, -bounds.Top); // Draw all the elements of the previewer DrawBackground(canvas, bounds); DrawGrid(canvas, tmxMap); DrawAllTilesInLayerNodes(canvas, tmxMap, tmxMap.LayerNodes); DrawAllCollidersInLayerNodes(canvas, tmxMap, tmxMap.LayerNodes); } report.Report(); return(bitmap); }