C# how to get a bitmap from a picturebox

bharathi picture bharathi · Aug 9, 2011 · Viewed 30.6k times · Source

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.

Answer

Evan Mulawski picture Evan Mulawski · Aug 9, 2011
Bitmap default_image = new Bitmap(pictureBox5.Image);

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