C# 如何从图片框中获取位图

发布于 2024-11-28 13:08:11 字数 212 浏览 5 评论 0原文

我的图片框中有一张图片。我想将该图像作为位图获取。

我的一行代码是:

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

但我得到的是:

default_image value=null;

任何人都可以帮助我。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

以酷 2024-12-05 13:08:11
Bitmap default_image = new Bitmap(pictureBox5.Image);

您永远不会实例化 Bitmap,这就是它为 null 的原因。

Bitmap default_image = new Bitmap(pictureBox5.Image);

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

话少心凉 2024-12-05 13:08:11

如果您使用 imageLocation 将图像放入 PictureBox

pbSourceImage.ImageLocation = openFile.FileName;

,则 PictureBox.Image 将为 null。

相反,使用加载图片

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

然后您将能够从 Image 属性进行克隆。

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.

帅气尐潴 2024-12-05 13:08:11

这是因为您没有图像,可能您有BackgroundImage
您需要用图像属性来填充您的图片。

This is because you do not have image, probably you have BackgroundImage.
You need to have Image properties fill with your picture.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文