I'm making a program with color quantization, after the quantization is finished, I want to display all the colors from the used color palette.
I can display them correctly once, but if u restart the process(press the button again) and say that there needs to be less colors or diffrent collors , the displayed colors are staying the colors from the first time I pressed the button.
This is what creates the boxes with colors and displays them on the screen :
private void CreatePallette(List<RGB> colorPallette)
{
var picture = new PictureBox();
int heightPixel = 0;
int widthPixel = 0;
for (int k = 0; k < colorPallette.Count(); k++)
{
Bitmap box = new Bitmap(25, 25);
RGB color = colorPallette[k];
Color adding = Color.FromArgb(color.GetR(), color.GetG(), color.GetB());
for (int i = 0; i < box.Height; i++)
{
for (int y = 0; y < box.Width; y++)
{
box.SetPixel(i, y, adding);
}
}
picture = new PictureBox
{
Name = "pictureBoxColor" + k,
Size = new Size(32, 32),
Location = new Point(50 + (25 * widthPixel), (25 * heightPixel) + 400),
Image = box
};
picture.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.Controls.Add(picture);
widthPixel++;
if(widthPixel == 33)
{
heightPixel++;
widthPixel = 0;
}
}
}
What I want that happens is if the color palette has 256 colors , 256boxes need to be on the form, if there are only 64 colors only 64 boxes need to be on the screen.