Created
July 20, 2022 05:24
-
-
Save Schroedi/613f5407a9428e33b39d1f2a9059c1ac to your computer and use it in GitHub Desktop.
Save PoE map to png
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="filename"></param> | |
/// <param name="data">LokiPoe.TerrainData.Layer0</param> | |
/// <param name="terrainSize">LokiPoe.TerrainData.Size</param> | |
/// <param name="bpr">LokiPoe.TerrainData.BytesPerRow</param> | |
public static void GeneratePng(string filename, ref byte[] data, Vector2i terrainSize, int bpr) | |
{ | |
Color TerrainColor(int v) | |
{ | |
var color = Color.Black; | |
switch (v) | |
{ | |
case 0: | |
color = Color.Transparent; | |
break; | |
case 1: | |
color = Color.White; | |
break; | |
case 2: | |
color = Color.Blue; | |
break; | |
case 3: | |
color = Color.Turquoise; | |
break; | |
case 4: | |
color = Color.Green; | |
break; | |
case 5: | |
color = Color.Yellow; | |
break; | |
case 6: | |
color = Color.Orange; | |
break; | |
case 7: | |
color = Color.Red; | |
break; | |
case 255: | |
color = Color.Gray; | |
break; | |
default: | |
color = Color.Pink; | |
break; | |
} | |
return Color.FromArgb(30, color); | |
} | |
var areaSize = terrainSize * 23; | |
var width = areaSize.X % 2 == 0 ? areaSize.X : areaSize.X + 1; | |
using (var img = new Bitmap(width, areaSize.Y)) | |
{ | |
var terrainBytes = data; | |
int dataIndex = 0; | |
for (int y = 0; y < areaSize.Y; y++) | |
{ | |
for (int x = 0; x < areaSize.X; x += 2) | |
{ | |
var b = terrainBytes[dataIndex + (x >> 1)]; | |
img.SetPixel(x, y, TerrainColor(b & 0xf)); | |
img.SetPixel(x+1, y, TerrainColor(b >> 4)); | |
} | |
dataIndex += bpr; | |
} | |
img.Save(filename); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment