public void Save() { using (new LockWait(ref _lock)) { if (map == null) { map = new GameColum[mapSize, mapSize]; for (int i = 0; i < mapSize; i++) { for (int j = 0; j < mapSize; j++) { map[i, j] = new GameColum() { posX = i, posY = j }; } } } Bitmap bitmap = Get(); bitmap.Save(path, ImageFormat.Png); APP.message.Publish(this, 0, null, bitmap); bitmap.Dispose(); } }
public void Load() { if (!File.Exists(path)) { Save(); } Bitmap bitmap = Bitmap.FromFile(path) as Bitmap; Bitmap nbt = new Bitmap(bitmap, new Size(mapSize, mapSize)); map = new GameColum[mapSize, mapSize]; for (int i = 0; i < mapSize; i++) { for (int j = 0; j < mapSize; j++) { Color col = nbt.GetPixel(j, mapSize - 1 - i); string hex = string.Format("{0:X2}{1:X2}{2:X2}{3:X2}", col.R, col.G, col.B, col.A); map[i, j] = new GameColum() { posX = i, posY = j, color = hex }; } } bitmap.Dispose(); nbt.Dispose(); }