Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# how to get a bitmap from a picturebox

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.

like image 526
bharathi Avatar asked Aug 09 '11 13:08

bharathi


2 Answers

Bitmap default_image = new Bitmap(pictureBox5.Image);

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

like image 107
Evan Mulawski Avatar answered Sep 18 '22 02:09

Evan Mulawski


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.

like image 40
adrianwadey Avatar answered Sep 18 '22 02:09

adrianwadey