1- using BF2WebAdmin . Common . Entities . Game ;
2- using SkiaSharp ;
3-
4- namespace BF2WebAdmin . Server ;
5-
6- public class MapStatsRenderer
7- {
8- public static Stream GetMapMovementPathImage ( string map , IEnumerable < ( Position , Rotation ) > movementPath1 , IEnumerable < ( Position , Rotation ) > movementPath2 )
9- {
10- if ( movementPath1 == null || ! movementPath1 . Any ( ) )
11- return null ;
12- if ( movementPath2 == null || ! movementPath2 . Any ( ) )
13- return null ;
14-
15- // crate a surface
16- var info = new SKImageInfo ( 700 , 700 ) ;
17- using var surface = SKSurface . Create ( info ) ;
18-
19- // the the canvas and properties
20- var canvas = surface . Canvas ;
21-
22- // make sure the canvas is blank
23- canvas . Clear ( SKColors . White ) ;
24-
25- var mapBackground = SKBitmap . Decode ( $ "Assets/{ map } .png") ;
26- var customOffset = GetCustomMapOffset ( map ) ;
27- var imageOffset = new SKPoint (
28- ( info . Width / 2f ) - ( mapBackground . Width / 2f ) + customOffset . x ,
29- ( info . Height / 2f ) - ( mapBackground . Height / 2f ) + customOffset . y
30- ) ;
31- canvas . DrawBitmap ( mapBackground , imageOffset ) ;
32-
33- // US heli path
34- var paint1 = new SKPaint
35- {
36- Color = SKColors . Blue ,
37- IsAntialias = true ,
38- Style = SKPaintStyle . Stroke ,
39- } ;
40- var path1 = new SKPath ( ) ;
41- path1 . MoveTo ( ToImageCoordinates ( movementPath1 . First ( ) . Item1 ) ) ;
42- foreach ( var ( pos , _) in movementPath1 )
43- {
44- path1 . LineTo ( ToImageCoordinates ( pos ) ) ;
45- }
46- canvas . DrawPath ( path1 , paint1 ) ;
47-
48- // China heli path
49- var paint2 = new SKPaint
50- {
51- Color = SKColors . Red ,
52- IsAntialias = true ,
53- Style = SKPaintStyle . Stroke ,
54- } ;
55- var path2 = new SKPath ( ) ;
56- path2 . MoveTo ( ToImageCoordinates ( movementPath2 . First ( ) . Item1 ) ) ;
57- foreach ( var ( pos , _) in movementPath2 )
58- {
59- path1 . LineTo ( ToImageCoordinates ( pos ) ) ;
60- }
61- canvas . DrawPath ( path2 , paint2 ) ;
62-
63- // draw some text
64- var paint = new SKPaint
65- {
66- Color = SKColors . White ,
67- IsAntialias = true ,
68- Style = SKPaintStyle . Fill ,
69- TextAlign = SKTextAlign . Center ,
70- TextSize = 32
71- } ;
72- var textPosition = new SKPoint ( info . Width / 2 , 40 ) ;
73- //var coord = new SKPoint(info.Width / 2, (info.Height + paint.TextSize) / 2);
74- canvas . DrawText ( "Round movements" , textPosition , paint ) ;
75-
76- // save the file
77- using var image = surface . Snapshot ( ) ;
78- using var data = image . Encode ( SKEncodedImageFormat . Png , 100 ) ;
79- using var stream = File . OpenWrite ( "output.png" ) ;
80- data . SaveTo ( stream ) ;
81-
82- var result = new MemoryStream ( ) ;
83- data . SaveTo ( result ) ;
84- return result ;
85-
86- SKPoint ToImageCoordinates ( Position pos )
87- {
88- return new SKPoint (
89- ( float ) pos . X + ( info . Width / 2f ) + customOffset . x ,
90- ( float ) pos . Y + ( info . Height / 2f ) + customOffset . y
91- ) ;
92- }
93- }
94-
95- private static ( float x , float y ) GetCustomMapOffset ( string map )
96- {
97- return map switch
98- {
99- //"dalian_2_v_2" => (30, -130),
100- _ => ( 0 , 0 )
101- } ;
102- }
103- }
1+ // using BF2WebAdmin.Common.Entities.Game;
2+ // using SkiaSharp;
3+ //
4+ // namespace BF2WebAdmin.Server;
5+ //
6+ // public class MapStatsRenderer
7+ // {
8+ // public static Stream GetMapMovementPathImage(string map, IEnumerable<(Position, Rotation)> movementPath1, IEnumerable<(Position, Rotation)> movementPath2)
9+ // {
10+ // if (movementPath1 == null || !movementPath1.Any())
11+ // return null;
12+ // if (movementPath2 == null || !movementPath2.Any())
13+ // return null;
14+ //
15+ // // crate a surface
16+ // var info = new SKImageInfo(700, 700);
17+ // using var surface = SKSurface.Create(info);
18+ //
19+ // // the the canvas and properties
20+ // var canvas = surface.Canvas;
21+ //
22+ // // make sure the canvas is blank
23+ // canvas.Clear(SKColors.White);
24+ //
25+ // var mapBackground = SKBitmap.Decode($"Assets/{map}.png");
26+ // var customOffset = GetCustomMapOffset(map);
27+ // var imageOffset = new SKPoint(
28+ // (info.Width / 2f) - (mapBackground.Width / 2f) + customOffset.x,
29+ // (info.Height / 2f) - (mapBackground.Height / 2f) + customOffset.y
30+ // );
31+ // canvas.DrawBitmap(mapBackground, imageOffset);
32+ //
33+ // // US heli path
34+ // var paint1 = new SKPaint
35+ // {
36+ // Color = SKColors.Blue,
37+ // IsAntialias = true,
38+ // Style = SKPaintStyle.Stroke,
39+ // };
40+ // var path1 = new SKPath();
41+ // path1.MoveTo(ToImageCoordinates(movementPath1.First().Item1));
42+ // foreach (var (pos, _) in movementPath1)
43+ // {
44+ // path1.LineTo(ToImageCoordinates(pos));
45+ // }
46+ // canvas.DrawPath(path1, paint1);
47+ //
48+ // // China heli path
49+ // var paint2 = new SKPaint
50+ // {
51+ // Color = SKColors.Red,
52+ // IsAntialias = true,
53+ // Style = SKPaintStyle.Stroke,
54+ // };
55+ // var path2 = new SKPath();
56+ // path2.MoveTo(ToImageCoordinates(movementPath2.First().Item1));
57+ // foreach (var (pos, _) in movementPath2)
58+ // {
59+ // path1.LineTo(ToImageCoordinates(pos));
60+ // }
61+ // canvas.DrawPath(path2, paint2);
62+ //
63+ // // draw some text
64+ // var paint = new SKPaint
65+ // {
66+ // Color = SKColors.White,
67+ // IsAntialias = true,
68+ // Style = SKPaintStyle.Fill,
69+ // TextAlign = SKTextAlign.Center,
70+ // TextSize = 32
71+ // };
72+ // var textPosition = new SKPoint(info.Width / 2, 40);
73+ // //var coord = new SKPoint(info.Width / 2, (info.Height + paint.TextSize) / 2);
74+ // canvas.DrawText("Round movements", textPosition, paint);
75+ //
76+ // // save the file
77+ // using var image = surface.Snapshot();
78+ // using var data = image.Encode(SKEncodedImageFormat.Png, 100);
79+ // using var stream = File.OpenWrite("output.png");
80+ // data.SaveTo(stream);
81+ //
82+ // var result = new MemoryStream();
83+ // data.SaveTo(result);
84+ // return result;
85+ //
86+ // SKPoint ToImageCoordinates(Position pos)
87+ // {
88+ // return new SKPoint(
89+ // (float)pos.X + (info.Width / 2f) + customOffset.x,
90+ // (float)pos.Y + (info.Height / 2f) + customOffset.y
91+ // );
92+ // }
93+ // }
94+ //
95+ // private static (float x, float y) GetCustomMapOffset(string map)
96+ // {
97+ // return map switch
98+ // {
99+ // //"dalian_2_v_2" => (30, -130),
100+ // _ => (0, 0)
101+ // };
102+ // }
103+ // }
0 commit comments