我有下面这段C#代码:
private void btn_getPixels_Click_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
listBox1.Items.Add("Pixel Color");
try
{
Bitmap img = new Bitmap(pictureBox1.Image);
Color c;
for (int i = 0; i < img.Width; i++)
{
for (int j = 0; j < img.Height; j++)
{
c = img.GetPixel(i, j);
listBox1.Items.Add(i + "," + j + " " + c.Name);
}
}
MessageBox.Show("SUCESSFULLY DONE");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}问题是,在外部循环完成后,我在listBox1中看不到任何结果。
你知道怎么解决这个问题吗?
发布于 2012-08-01 18:41:53
你的代码运行成功(我检查过了)。这似乎是因为img.Width或img.Height的值很大,而您的程序仍在运行(因此您看不到结果)。尝试此循环并查看结果:
for (int i = 0; i < 50; i++)
{
for (int j = 0; j < 50; j++)
{
...发布于 2012-08-01 18:42:54
我对你的代码没有任何问题:

当然,mb你必须改变宽度和高度来测试。
https://stackoverflow.com/questions/11757317
复制相似问题