10

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.

3 Answers 3

19
Bitmap default_image = new Bitmap(pictureBox5.Image);

You are never instantiating a Bitmap which is why it is null.

Sign up to request clarification or add additional context in comments.

3 Comments

If he's getting null out of Image.Clone(), then calling the constructor with the same image property isn't going to do very much either.
@MGZero: It is my understanding that it is null because you cannot cast a Image object to a Bitmap.
Bitmap is inherited from Image..sooo...yes, you are correct. +1 now that I'm certain :)
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.

Comments

0

This is because you do not have image, probably you have BackgroundImage. You need to have Image properties fill with your picture.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.