C # how to get bitmap from image window

I have an image in a picture. I want to get this image as a bitmap.

My one line code:

Bitmap default_image = (Bitmap)pictureBox5.Image.Clone();

But I get:

default_image value=null;

Can anybody help me.

+8
c # bitmap picturebox bitmapimage
source share
3 answers
 Bitmap default_image = new Bitmap(pictureBox5.Image); 

You never create an instance of Bitmap , so it is null .

+15
source share

This is because you do not have an image, perhaps you have a BackgroundImage . You must have Image properties.

0
source share

If you received the image in a PictureBox using imageLocation

 pbSourceImage.ImageLocation = openFile.FileName; 

then PictureBox.Image will be null.

Instead, upload an image using

 pbSourceImage.Image = Image.FromFile(openFile.FileName); 

Then you can clone from the Image property.

0
source share

All Articles