Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.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# 将PictureBox.Image添加到位图列表_C#_Image_Bitmap - Fatal编程技术网

C# 将PictureBox.Image添加到位图列表

C# 将PictureBox.Image添加到位图列表,c#,image,bitmap,C#,Image,Bitmap,我有一个位图和PictureBox的列表。我想将PictureBox的图像添加到列表中。 此代码: pictureBox1.Load(openFileDialog1.FileName); loadedImages.Add(new Bitmap(pictureBox1.Image)); 导致NullReference异常: 教程\u Picture\u Viewer.exe中发生类型为“System.NullReferenceException”的未处理异常 其他信息:对象引用未设置为对象的实例

我有一个位图和PictureBox的列表。我想将PictureBox的图像添加到列表中。 此代码:

pictureBox1.Load(openFileDialog1.FileName);
loadedImages.Add(new Bitmap(pictureBox1.Image));
导致NullReference异常:

教程\u Picture\u Viewer.exe中发生类型为“System.NullReferenceException”的未处理异常

其他信息:对象引用未设置为对象的实例


非常感谢您的帮助。

如果
loadedImages
列表
请尝试:
loadedImages.Add((位图)pictureBox1.Image)
loadedImages
实际上是我的
列表
。我尝试了你的代码,但它给出了相同的错误。PB是否确实加载了图像?如果我删除
LoadeImage.Add(…)
行,PictureBox加载图像时不会出现问题。是否初始化LoadeImage?最好也显示初始化代码,这样我们就不必猜测了。