问题
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.
回答1:
Bitmap default_image = new Bitmap(pictureBox5.Image);
You are never instantiating a Bitmap
which is why it is null
.
回答2:
If you got the image into the PictureBox by using imageLocation
pbSourceImage.ImageLocation = openFile.FileName;
then PictureBox.Image will be null.
Instead, load the picture using
pbSourceImage.Image = Image.FromFile(openFile.FileName);
Then you will be able to clone from the Image property.
回答3:
This is because you do not have image, probably you have BackgroundImage. You need to have Image properties fill with your picture.
来源:https://stackoverflow.com/questions/6996987/c-sharp-how-to-get-a-bitmap-from-a-picturebox