C#如何从picturebox获取位图
我在图片盒里有一张照片。我想把那个图像做成位图 我的单行代码是:C#如何从picturebox获取位图,c#,bitmap,picturebox,bitmapimage,C#,Bitmap,Picturebox,Bitmapimage,我在图片盒里有一张照片。我想把那个图像做成位图 我的单行代码是: Bitmap default_image=(位图)pictureBox5.image.Clone() 但我得到的是: default_image value=null 有人能帮我吗 Bitmap default_image = new Bitmap(pictureBox5.Image); 您从未实例化位图,这就是为什么它为空这是因为您没有图像,可能您有背景图像。 您需要用图片填充图像属性。如果您使用imageLocation将图
Bitmap default_image=(位图)pictureBox5.image.Clone()代码>
但我得到的是:
default_image value=null代码>
有人能帮我吗
Bitmap default_image = new Bitmap(pictureBox5.Image);
您从未实例化位图
,这就是为什么它为空
这是因为您没有图像,可能您有背景图像。
您需要用图片填充图像属性。如果您使用imageLocation将图像放入PictureBox中
pbSourceImage.ImageLocation = openFile.FileName;
然后PictureBox.Image将为空
相反,请使用
pbSourceImage.Image = Image.FromFile(openFile.FileName);
然后您就可以从Image属性进行克隆。如果他从Image.clone()中得到null,那么用相同的Image属性调用构造函数也不会有多大作用。@MGZero:据我所知,它是null的,因为您无法将Image对象强制转换为位图。位图是从Image继承的。..sooo…是的,你说得对+1现在我可以肯定:)