gpt4 book ai didi

c# - 将 PictureBox 中的图像转换为位图

转载 作者:可可西里 更新时间:2023-11-01 08:39:47 26 4
gpt4 key购买 nike

我使用以下代码将 PictureBox 中的图像转换为位图:

bmp = (Bitmap)pictureBox2.Image;

但我得到的结果是 bmp = null。谁能告诉我该怎么做?

最佳答案

As per my understanding your have not assigned PictureBox's Imageproperty, so that it is returning null on type cast.

PictureBox property automatically convert the Image format and if you see the tooltip on Image property, it will Show System.Drawing.Bitmap. Check your imageproperty is correctly assigned.

检查这个,它正在我这边工作。

private void button1_Click(object sender, EventArgs e)
{
var bmp = (Bitmap)pictureBox1.Image;
}

private void TestForm12_Load(object sender, EventArgs e)
{
pictureBox1.Image = Image.FromFile("c:\\url.gif");
}

///使用 BitMap 类

 Bitmap bmp = new Bitmap(pictureBox2.Image);

您可以直接将 pictureBox2.Image 转换为 Bitmap,也可以使用 Bitmap 类转换为 Bitmap 类对象。

引用: Bitmap Constructor (Image) .

You can find more options here with the Bitmap Class

关于c# - 将 PictureBox 中的图像转换为位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10651686/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com