Vb.net Visual Basic.net中图像的透明度?

Vb.net Visual Basic.net中图像的透明度?,vb.net,image,Vb.net,Image,我的表格上有一个图片框,我在其中添加了一张图片。这张图片有一个透明的背景,但不幸的是,它似乎丢失在图片框中。。。我猜这是因为图片框的背景色属性设置为灰色(默认值)。不过,我看不到任何“透明”选项 你知道我该怎么做吗?根据你要完成的任务,有几种不同的方法 一些示例是- 使位图透明 Dim bmp As Bitmap = Bitmap.FromFile("test.bmp") bmp.MakeTransparent(Color.Magenta) ' magenta in bitmap will be

我的表格上有一个图片框,我在其中添加了一张图片。这张图片有一个透明的背景,但不幸的是,它似乎丢失在图片框中。。。我猜这是因为图片框的背景色属性设置为灰色(默认值)。不过,我看不到任何“透明”选项


你知道我该怎么做吗?

根据你要完成的任务,有几种不同的方法

一些示例是-

使位图透明

Dim bmp As Bitmap = Bitmap.FromFile("test.bmp") bmp.MakeTransparent(Color.Magenta) ' magenta in bitmap will be transparent PictureBox1.Image = bmp PictureBox1.BackColor = Color.Transparent 将bmp设置为位图=Bitmap.FromFile(“test.bmp”) bmp.MakeTransparent(Color.Magenta)“位图中的洋红将是透明的 PictureBox1.Image=bmp 使图片框透明

Dim bmp As Bitmap = Bitmap.FromFile("test.bmp") bmp.MakeTransparent(Color.Magenta) ' magenta in bitmap will be transparent PictureBox1.Image = bmp PictureBox1.BackColor = Color.Transparent PictureBox1.BackColor=颜色。透明 如果你真的需要透明图像,我建议你不要使用picturebox,直接渲染一个透明位图。

如果你想让picturebox后面的控件显示,也就是说,你想让你的图像以透明背景显示,试着直接在表单上绘制


回到VB6时代,我们可以通过挂接窗体的“重画”事件或其他什么来实现这一点…

在VB中的大多数控件上,在对象的Backcolor属性中,有一个透明度选项。这在VB2008中运行良好,但在VB2005中,必须将其.parent属性设置为后面的对象(以我的经验,无论如何)


希望这能有所帮助,

我知道这是一个老话题,但我想我会为任何想为Windows窗体寻找简单解决方案的人发布我提出的解决方案。假设你有PictureBox1和PictureBox2。您希望PictureBox2覆盖在PictureBox1上。确保PictureBox1背景设置为透明。然后,您可以通过编程方式设置:

PictureBox2.Parent = PictureBox1

Magic

透明图像,您还可以使用Adobe Photoshop删除白色/黑色背景(观看如何创建透明背景的教程) 或者使用下面的代码

PictureBox1.BackColor = Color.Transparent
SetStyle(ControlStyles.SupportsTransparentBackColor, True)

如果pictureBox的面板有背景图像,则此操作将不起作用。这将起作用,但仅当您的图片不移动时。否则,您将不得不进行自定义无效和自定义重新绘制。。。这是一个大问题……在VS2005中,将父对象设置为后台控件为我实现了这一点。