/// <summary> /// bmpからGridMapを生成 /// </summary> /// <param name="bitmap"></param> public GridMap(Bitmap bitmap) { W = bitmap.Width; H = bitmap.Height; M = new Grid[W, H]; BitmapAccess access = new BitmapAccess(bitmap); access.BeginAccess(); // bmpからGridMapを生成 for (int x = 0; x < W; ++x) { for (int y = 0; y < H; ++y) { Color c = access[x, y]; if (c == GridColor_Fill) { // 障害物 this[x, y] = Grid.Fill; } else if (c == GridColor_Free) { // 何もないところ this[x, y] = Grid.Free; } else if (c == GridColor_RedArea) { // 異常地帯 壁の中 this[x, y] = Grid.RedArea; } else if (c == GridColor_GreenArea) { // 位置補正エリア this[x, y] = Grid.GreenArea; } else if (c == GridColor_BlueArea) { // スローエリア this[x, y] = Grid.BlueArea; } else { // それ以外 this[x, y] = Grid.Unknown; } } } access.EndAccess(); }
/// <summary> /// GridMapからBMP更新 /// </summary> /// <returns></returns> public Bitmap UpdateBitmap() { BitmapAccess MapAccess = new BitmapAccess(img); MapAccess.BeginAccess(); for (int x = 0; x < W; ++x) { for (int y = 0; y < H; ++y) { Color cl = Color.Yellow; switch (this[x, y]) { case Grid.Fill: cl = Color.Black; break; case Grid.Free: cl = Color.White; break; case Grid.RedArea: cl = Color.Red; break; case Grid.BlueArea: cl = Color.Blue; break; case Grid.GreenArea: cl = Color.Green; break; case Grid.Unknown: cl = Color.LightGray; break; } MapAccess[x, y] = cl; } } MapAccess.EndAccess(); return(img); }