C# 将PictureBox.Image添加到位图列表
我有一个位图和PictureBox的列表。我想将PictureBox的图像添加到列表中。 此代码: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”的未处理异常 其他信息:对象引用未设置为对象的实例
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?最好也显示初始化代码,这样我们就不必猜测了。