1
我正在尝试在定时器的滴答功能中将位图图像添加到List<Image>
。计时器有100ms的刻度,并使用下面的代码:将屏幕上的区域添加到图像列表中
private void GifTimer_Tick(object sender, EventArgs e)
{
using (var bmp = new Bitmap(selection.Width, selection.Height, PixelFormat.Format32bppPArgb))
{
using (var graphics = Graphics.FromImage(bmp)) graphics.CopyFromScreen(selection.Left, selection.Top, 0, 0, bmp.Size);
images.Add(bmp); //Adds null values apparently.
}
}
我跑了一些断点调试,发现bmp
不为空,且具有正确的宽度和高度,根据该选择。我在其他地方使用相同的代码来实现其他目的,并且按预期工作。但是,当这个位图添加到我的列表中时,它将返回null。
我在这里错过了什么吗?该列表在我的构造函数中初始化为new List<Image>();
。
优秀,非常感谢你! – Dragonphase
@Dragonphase不客气:) –