gpt4 book ai didi

c# - 我如何遍历 FileInfo[] 并更新 Paint 事件?

转载 作者:太空宇宙 更新时间:2023-11-03 15:45:48 25 4
gpt4 key购买 nike

我有这个代码:

private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
pixelscoordinatesinrectangle = new List<Point>();
pixelscoordinatesinrectangle = pointsAffected.ToList();
DrawIt = false;
for (int i = 0; i < trackBar1FileInfo.Length; i++)
{
DrawIt = true;
trackBar1.Value = i;
LoadPictureAt(trackBar1.Value, sender);
pictureBox1.Refresh();
pixelscoordinatesinrectangle = pointsAffected.ToList();
MessageBox.Show(pixelscoordinatesinrectangle.Count.ToString());
}
}

trackBar1FileInfo 是 FileInfo[] 并且包含 5006 个文件,例如在

index 0 I see test.gif 
index 1 I see test1.gif
index 2 test2.gif
and so on....

在 trackBar1 滚动事件中,当我左右移动 trackBar 时,它会更改 pictureBox1 中的图像。

LoadPictureAt 是:

private bool LoadPictureAt(int nIndex, object c)
{

{
bool bRet = false;

if (nIndex >= 0 && nIndex < trackBar1FileInfo.Length)
{
if (c.Equals(trackBar1))


pictureBox1.Load(trackBar1FileInfo[nIndex].FullName);
bRet = true;

}
if (bitmaps != null)
{
if (nIndex >= 0 && nIndex < bitmaps.Length)
{
if (c.Equals(trackBar2))
pictureBox1.Image = bitmaps[nIndex];
bRet = true;
}
}
return bRet;

}
}

我在 trackBar1 滚动事件中使用 LoadPictureAt 方法来显示图像。

pixelscoordinatesinrectangle 是列表

在绘画事件中我有:

private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
if (cloudPoints != null)
{
if (DrawIt)
{
e.Graphics.DrawRectangle(pen, rect);
pointsAffected = cloudPoints.Where(pt => rect.Contains(pt));

CloudEnteringAlert.pointtocolorinrectangle = pointsAffected.ToList();
Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height, PixelFormat.Format32bppArgb);
CloudEnteringAlert.Paint(e.Graphics, 1, 200, bmp);
}
}
}

问题是:

  1. pictureBox1中的图片在循环时没有变化。

  2. List pixelcoordinatesinrectangle 永远不会改变,如果它有 203 个项目,它将保持 203 个项目。

这里的想法是遍历所有图像并更新 pictureBox1 并执行绘制事件代码,这样每次每张图像列表 pixelscoordinatesinrectangle 也会更新。

现在发生的是只有 trackBar1 移动到 0,然后一个一个地向上移动。所有其他的都没有改变。

最佳答案

循环在主 UI 上阻塞。使用单独的线程/后台 worker 进行更新。看看这里,可能重复:Creating a statusfield for users

关于c# - 我如何遍历 FileInfo[] 并更新 Paint 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28207503/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com