C# 如何从图片框中获取位图
我的图片框中有一张图片。我想将该图像作为位图获取。
我的一行代码是:
Bitmap default_image = (Bitmap)pictureBox5.Image.Clone();
但我得到的是:
default_image value=null;
任何人都可以帮助我。
I have a image in picturebox. I want to get that image as a Bitmap.
My one line code is:
Bitmap default_image = (Bitmap)pictureBox5.Image.Clone();
But what i am getting is:
default_image value=null;
Can anyone help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您永远不会实例化
Bitmap
,这就是它为null
的原因。You are never instantiating a
Bitmap
which is why it isnull
.如果您使用 imageLocation 将图像放入 PictureBox
,则 PictureBox.Image 将为 null。
相反,使用加载图片
然后您将能够从 Image 属性进行克隆。
If you got the image into the PictureBox by using imageLocation
then PictureBox.Image will be null.
Instead, load the picture using
Then you will be able to clone from the Image property.
这是因为您没有图像,可能您有BackgroundImage。
您需要用图像属性来填充您的图片。
This is because you do not have image, probably you have BackgroundImage.
You need to have Image properties fill with your picture.