public void DrawImage(Image image, IntXYPair position) { //load the colors, and keep track of the color conversion Dictionary <int, int> colorMap = new Dictionary <int, int> { // black and white [15] = 15, [16] = 16 }; //get the correct number for each color in the image int initialIndex = colors.Count(); for (int i = 0; i < image.Colors.Count; i++) { if (colors.Any(x => x.ToArgb() == image.Colors[i].ToArgb())) { colorMap[i] = colors.FindIndex(x => x.ToArgb() == image.Colors[i].ToArgb()); } else { colors.Add(image.Colors[i]); colorMap[i] = colors.Count - 1; } } //calculating where to start and where to end int rowStart = Math.Max(0, 0 - position.y); int rowEnd = Math.Min(bitmap.GetLength(1), position.y + image.Bitmap.Count) - position.y; int leftLimit = Math.Max(0, 0 - position.x); int rightLimit = Math.Min(bitmap.GetLength(0), position.x + image.Bitmap[0].Length) - position.x; for (int y = rowStart; y < rowEnd; y++) { for (int x = leftLimit; x < rightLimit; x++) { char currentPixel = image.Bitmap[y][x]; if (currentPixel != 'T') { if (currentPixel == 'W') { bitmap[x + position.x, y + position.y] = 15; } else if (currentPixel == 'Z') { bitmap[x + position.x, y + position.y] = 16; } else { bitmap[x + position.x, y + position.y] = colorMap[Convert.ToInt32(image.Bitmap[y][x].ToString())]; } } } } }
public void DrawImage(Image image, int x, int y) { DrawImage(image, new IntXYPair(x, y)); }