[英]C# how to get a bitmap from a picturebox
I have a image in picturebox. 我在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. 谁能帮我。
Bitmap default_image = new Bitmap(pictureBox5.Image);
你永远不会实例化一个Bitmap
,这就是为什么它是null
。
If you got the image into the PictureBox by using imageLocation 如果使用imageLocation将图像放入PictureBox中
pbSourceImage.ImageLocation = openFile.FileName;
then PictureBox.Image will be null. 然后PictureBox.Image将为null。
Instead, load the picture using 而是使用加载图片
pbSourceImage.Image = Image.FromFile(openFile.FileName);
Then you will be able to clone from the Image property. 然后,您将能够从Image属性进行克隆。
This is because you do not have image, probably you have BackgroundImage . 这是因为你没有图像,可能你有BackgroundImage 。 You need to have Image properties fill with your picture.
您需要在图片属性中填充图片。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.