C# how to get a bitmap from a picturebox

雨燕双飞 提交于 2019-12-23 07:51:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!