[英]C# how to get a bitmap from a picturebox
我在picturebox中有一個圖像。 我想將該圖像作為位圖。
我的一行代碼是:
Bitmap default_image = (Bitmap)pictureBox5.Image.Clone();
但我得到的是:
default_image value=null;
誰能幫我。
Bitmap default_image = new Bitmap(pictureBox5.Image);
你永遠不會實例化一個Bitmap
,這就是為什么它是null
。
如果使用imageLocation將圖像放入PictureBox中
pbSourceImage.ImageLocation = openFile.FileName;
然后PictureBox.Image將為null。
而是使用加載圖片
pbSourceImage.Image = Image.FromFile(openFile.FileName);
然后,您將能夠從Image屬性進行克隆。
這是因為你沒有圖像,可能你有BackgroundImage 。 您需要在圖片屬性中填充圖片。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.