Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将屏幕区域添加到图像列表中_C#_Winforms_Image_List_Graphics - Fatal编程技术网

C# 将屏幕区域添加到图像列表中

C# 将屏幕区域添加到图像列表中,c#,winforms,image,list,graphics,C#,Winforms,Image,List,Graphics,我正在尝试将位图图像添加到计时器的勾号函数中的列表中。计时器有一个100毫秒的刻度,并使用以下代码: private void GifTimer_Tick(object sender, EventArgs e) { using (var bmp = new Bitmap(selection.Width, selection.Height, PixelFormat.Format32bppPArgb)) { using (var graphics = Graphics

我正在尝试将位图图像添加到计时器的勾号函数中的列表中。计时器有一个100毫秒的刻度,并使用以下代码:

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

我是不是遗漏了什么?该列表被初始化为新列表;在我的构造函数中。

不要使用自动处置位图:

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);