BiomePainter.RegionUtil.SelectChunks C# (CSharp) Method

SelectChunks() public static method

public static SelectChunks ( Bitmap b, Color selectionColor ) : void
b System.Drawing.Bitmap
selectionColor Color
return void
        public static void SelectChunks(Bitmap b, Color selectionColor)
        {
            using (Graphics g = Graphics.FromImage(b))
            {
                g.SetClip(CLIP);
                Brush brush = new SolidBrush(selectionColor);
                for (int chunkX = 0; chunkX < 32; chunkX++)
                {
                    for (int chunkZ = 0; chunkZ < 32; chunkZ++)
                    {
                        bool shouldSelect = false;
                        for (int x = 0; x < 16; x++)
                        {
                            for (int z = 0; z < 16; z++)
                            {
                                if (b.GetPixel(OFFSETX + chunkX * 16 + x, OFFSETY + chunkZ * 16 + z).ToArgb() == selectionColor.ToArgb())
                                {
                                    shouldSelect = true;
                                    break;
                                }
                            }
                            if (shouldSelect)
                                break;
                        }

                        if (shouldSelect)
                            g.FillRectangle(brush, OFFSETX + chunkX * 16, OFFSETY + chunkZ * 16, 16, 16);
                    }
                }
            }
        }

Usage Example

Esempio n. 1
0
 private void btnSelectChunks_Click(object sender, EventArgs e)
 {
     UpdateStatus("Expanding selection");
     RegionUtil.SelectChunks(imgRegion.Layers[SELECTIONLAYER].Image, imgRegion.SelectionColor);
     UpdateStatus("");
     imgRegion.Redraw();
     history.RecordSelectionState(imgRegion.Layers[SELECTIONLAYER].Image, "Select Chunks");
 }