private Bitmap generateCellTypeImage(CellType[,] map, CellType typeMask) { int width = map.GetUpperBound(0) + 1; int height = map.GetUpperBound(1) + 1; byte[] buffer = new byte[width * height * 3]; int i = 0; for (int y = height - 1; y >= 0; y--) { for (int x = 0; x < width; x++) { byte color = (map[x, y] & typeMask) != 0 ? (byte)255 : (byte)0; buffer[i++] = color; buffer[i++] = color; buffer[i++] = color; } } GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); Bitmap bmp = new Bitmap(width, height, width * 3, PixelFormat.Format24bppRgb, handle.AddrOfPinnedObject()); this.imageHandles.Add(handle); return bmp; }
private Bitmap generateCellTypeImage(CellType[,] map) { int width = map.GetUpperBound(0) + 1; int height = map.GetUpperBound(1) + 1; byte[] buffer = new byte[width * height * 3]; int i = 0; for (int y = height - 1; y >= 0; y--) { for (int x = 0; x < width; x++) { CellType type = map[x, y]; if (type.HasFlag(CellType.Sloped)) buffer[i] = buffer[i + 1] = buffer[i + 2] = 63; if (type.HasFlag(CellType.Cliff)) buffer[i] = buffer[i + 1] = buffer[i + 2] = 127; if (type.HasFlag(CellType.Water)) buffer[i] = 255; if (type.HasFlag(CellType.Building)) buffer[i + 1] = 255; if (type.HasFlag(CellType.Lava)) buffer[i + 2] = 255; i += 3; } } GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); Bitmap bmp = new Bitmap(width, height, width * 3, PixelFormat.Format24bppRgb, handle.AddrOfPinnedObject()); this.imageHandles.Add(handle); return bmp; }