@@ -70,7 +70,8 @@ internal static Bitmap GenerateImage(
7070 }
7171 catch ( Exception ex )
7272 {
73- System . Diagnostics . Trace . WriteLine ( $ "[CRITICAL] Failed to decode asset { texture . Path } : { ex . Message } ") ;
73+ System . Diagnostics . Trace . WriteLine (
74+ $ "[CRITICAL] Failed to decode asset { texture . Path } : { ex . Message } ") ;
7475 }
7576 }
7677 }
@@ -100,24 +101,23 @@ internal static Bitmap GenerateImage(
100101 sortedTiles . Sort ( ( a , b ) => a . Layer . CompareTo ( b . Layer ) ) ;
101102
102103 // 3. THE GRAPHICS FIX: Open the graphics envelope ONCE for the whole map sheet
103- using ( var graph = Graphics . FromImage ( background ) )
104- {
105- // Optional: Ensure a clean alpha base line across the canvas space
106- graph . Clear ( System . Drawing . Color . Transparent ) ;
104+ using var graph = Graphics . FromImage ( background ) ;
105+ // Optional: Ensure a clean alpha base line across the canvas space
106+ graph . Clear ( System . Drawing . Color . Transparent ) ;
107107
108- // Blit all 100 tiles rapidly into the open graphics pipeline context
109- foreach ( var slice in sortedTiles )
108+ // Blit all 100 tiles rapidly into the open graphics pipeline context
109+ foreach ( var slice in sortedTiles )
110+ {
111+ if ( slice . Image != null )
110112 {
111- if ( slice . Image != null )
112- {
113- graph . DrawImage ( slice . Image ,
114- new Rectangle ( slice . X , slice . Y , slice . Image . Width , slice . Image . Height ) ) ;
115- }
113+ graph . DrawImage ( slice . Image ,
114+ new Rectangle ( slice . X , slice . Y , slice . Image . Width , slice . Image . Height ) ) ;
116115 }
117- } // GDI+ flushes all operations to system memory and closes cleanly here ONCE
116+ }
118117
119118 return background ;
120119 }
120+
121121 /// <summary>
122122 /// Generates a grid overlay.
123123 /// </summary>
@@ -187,42 +187,36 @@ internal static Bitmap GenerateGlyphOverlay(
187187
188188 if ( glyphMap == null || glyphMap . Count == 0 ) return overlayFrame ;
189189
190- using ( var g = Graphics . FromImage ( overlayFrame ) )
191- {
192- // THE GRIP: Enable high-fidelity vector text rendering
193- g . SmoothingMode = System . Drawing . Drawing2D . SmoothingMode . HighQuality ;
194- g . TextRenderingHint = System . Drawing . Text . TextRenderingHint . AntiAliasGridFit ;
190+ using var g = Graphics . FromImage ( overlayFrame ) ;
191+ // THE GRIP: Enable high-fidelity vector text rendering
192+ g . SmoothingMode = System . Drawing . Drawing2D . SmoothingMode . HighQuality ;
193+ g . TextRenderingHint = System . Drawing . Text . TextRenderingHint . AntiAliasGridFit ;
195194
196- // Establish string formatting rules to ensure symbols center perfectly inside the cell block
197- using ( var sf = new StringFormat ( ) )
198- {
199- sf . Alignment = StringAlignment . Center ;
200- sf . LineAlignment = StringAlignment . Center ;
195+ // Establish string formatting rules to ensure symbols center perfectly inside the cell block
196+ using var sf = new StringFormat ( ) ;
197+ sf . Alignment = StringAlignment . Center ;
198+ sf . LineAlignment = StringAlignment . Center ;
201199
202- foreach ( var kp in glyphMap )
203- {
204- int tileIndex = kp . Key ;
205- OverlayGlyph glyph = kp . Value ;
200+ foreach ( var kp in glyphMap )
201+ {
202+ int tileIndex = kp . Key ;
203+ OverlayGlyph glyph = kp . Value ;
206204
207- if ( string . IsNullOrEmpty ( glyph . Symbol ) ) continue ;
205+ if ( string . IsNullOrEmpty ( glyph . Symbol ) ) continue ;
208206
209- // Map flat index location straight into 2D chessboard pixel boundaries
210- int cellX = ( tileIndex % width ) * textureSize ;
211- int cellY = ( tileIndex / width ) * textureSize ;
207+ // Map flat index location straight into 2D chessboard pixel boundaries
208+ int cellX = ( tileIndex % width ) * textureSize ;
209+ int cellY = ( tileIndex / width ) * textureSize ;
212210
213- // Calculate the exact destination boundaries of the chessboard cell space
214- var targetRect = new RectangleF ( cellX , cellY , textureSize , textureSize ) ;
211+ // Calculate the exact destination boundaries of the chessboard cell space
212+ var targetRect = new RectangleF ( cellX , cellY , textureSize , textureSize ) ;
215213
216- // Build font family profile dynamically
217- var fontStyle = glyph . IsBold ? System . Drawing . FontStyle . Bold : System . Drawing . FontStyle . Regular ;
218- using ( var font = new Font ( glyph . FontName , glyph . FontSize , fontStyle ) )
219- using ( var brush = new System . Drawing . SolidBrush ( glyph . Color ) )
220- {
221- // Draw the crisp vector character straight onto the bitmap buffer plane
222- g . DrawString ( glyph . Symbol , font , brush , targetRect , sf ) ;
223- }
224- }
225- }
214+ // Build font family profile dynamically
215+ var fontStyle = glyph . IsBold ? System . Drawing . FontStyle . Bold : System . Drawing . FontStyle . Regular ;
216+ using var font = new Font ( glyph . FontName , glyph . FontSize , fontStyle ) ;
217+ using var brush = new System . Drawing . SolidBrush ( glyph . Color ) ;
218+ // Draw the crisp vector character straight onto the bitmap buffer plane
219+ g . DrawString ( glyph . Symbol , font , brush , targetRect , sf ) ;
226220 }
227221
228222 return overlayFrame ;
0 commit comments