0
I’m doing a program to do the image limiarization, and I wanted to show a graph with which grayscale most appear in the image. The first time the program works normal, but the second time it gives this error:
"A graph element named '0' already exists in 'Seriescollection'"
I’ve tried using the Grafico.Series.Clear();
and several other types of code to clean the graph but nothing helped.
This is my current main:
private Image imagem;
private Image cinza;
Series seri;
Color corlabel;
Ocorrencia cla = new Ocorrencia();
bool rad;
public Form1()
{
InitializeComponent();
}
private void salvarImagemToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Images|*.bmp;";
if (sfd.ShowDialog() == DialogResult.OK)
{
string ext = System.IO.Path.GetExtension(sfd.FileName);
PBS.Image.Save(sfd.FileName);
}
}
catch
{
MessageBox.Show("Erro ao salvar a imagem tente novamente");
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void carregarImagemToolStripMenuItem_Click(object sender, EventArgs e)
{
corlabel = Color.FromArgb(255, 0, 0);
OpenFileDialog dialog = new OpenFileDialog();
dialog.Title = "Selecione um arquivo de imagem";
dialog.InitialDirectory = "C:\\";
dialog.Filter = "Imagens(*.bmp; *.jpg; *.gif)|*.bmp; *.jpg; *.gif | Todos os Arquivos(*.*)| *.*";
dialog.RestoreDirectory = false;
if (dialog.ShowDialog() == DialogResult.OK)
{
imagem = Image.FromFile(dialog.FileName);
PBC.Image = Image.FromFile(dialog.FileName);
/// Fazendo imagem em tons de cinza
}
}
private void button1_Click(object sender, EventArgs e)
{
}
private void button1_Click_1(object sender, EventArgs e)
{
label2.ForeColor = corlabel;
label2.Text = "Em processo";
cinza = (Image)imagem.Clone();
Bitmap img = new Bitmap(cinza);
Bitmap imgc = cla.Monocromatico(img);
PBM.Image = imgc;
this.Refresh();
List<Ocorrencia> lista = cla.ContarOcorrencias(img);
/// jogando no grafico
lista = lista.OrderBy(x => x.Quantidade).ToList();
Grafico.Legends[0].LegendStyle = LegendStyle.Table;
int[] seriesArray = new int[lista.Count];
int[] pointsArray = new int[lista.Count];
int i = 0;
foreach (Ocorrencia o in lista)
{
seriesArray[i++] = o.Cor;
}
i = 0;
foreach (Ocorrencia o in lista)
{
pointsArray[i++] = o.Quantidade;
}
Grafico.Series.Clear();
for (int ib = 0; ib < lista.Count; ib++)
{
// ERRO -> linha em que o erro aparece
seri = Grafico.Series.Add(Convert.ToString(seriesArray[ib]));
seri.Points.Add((pointsArray[ib]));
}
int limiar = cla.CalcularLimiar(lista);
LBLimiar.Text = Convert.ToString(limiar);
if (radioButton1.Checked == true) {
rad = true;
} else {
rad = false;
}
Bitmap imgl = cla.Limiarizacao(img, limiar,rad);
PBS.Image = img;
corlabel = Color.FromArgb(50, 205, 50);
label2.ForeColor = corlabel;
label2.Text = "Concluido";
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
}
}
}
That one
SeriesCollection
error is the classChart.SeriesCollection
(Excel? )? This classSeries
is yours? If so, what is her code?– Pedro Gaspar
@Pedrogaspar I’m not sure, but when I researched to fix this mistake I found people relating the two. This Class
Series
is from c itself#.– Tiago Cunico