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

时间:2022-12-08 00:01:16

I have a picture box on my form, which I add a picture to. This picture has a transparent background, but unfortunately, it seems lost in the picture box... I'm guessing that's because the picture box's background colour property is set to grey (the default). I can't see any option for "transparent" though.

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

Any idea how I can do it?

知道怎么做吗?

5 个解决方案

#1


Depending on what you are trying to accomplish there's several different ways to go about it.

根据您要完成的任务,有几种不同的方法可以实现。

Some examples are -

一些例子是 -

Make bitmap transparent

使位图透明

Dim bmp As Bitmap = Bitmap.FromFile("test.bmp")
bmp.MakeTransparent(Color.Magenta) ' magenta in bitmap will be transparent
PictureBox1.Image = bmp

Make the picture box transparent

使图片框透明

PictureBox1.BackColor = Color.Transparent

If you really need a transparent image I would suggest not using the picturebox and just render a transparent bitmap directly.

如果你真的需要透明图像,我建议不要使用图片框,只是直接渲染透明位图。

#2


If you want the controls behind the PictureBox to show, ie. you want your image displayed with a transparent background, try drawing straight on the form itself.

如果你想要显示PictureBox背后的控件,即。如果希望图像以透明背景显示,请尝试直接在表单上绘图。

Back in the days of VB6 we could do this by hooking onto the Form's "Redraw" event or something...

回到VB6的时代,我们可以通过挂钩Form的“Redraw”事件或其他东西来做到这一点......

#3


On most controls in VB, in the Backcolor property of the object, there is an option for transparency. This works fine in VB2008, but in VB2005, you must then set it's .parent property to the object behind (well, in my experience anyways.)

在VB中的大多数控件中,在对象的Backcolor属性中,有一个透明选项。这在VB2008中工作正常,但是在VB2005中,你必须将它的.parent属性设置为后面的对象(好吧,根据我的经验)。

Hope this helps,

希望这可以帮助,

#4


I know this is an old topic, but I figured I'd post the solution I came up with for anyone looking for a simple solution for Windows Forms. Say you have PictureBox1 and PictureBox2. You want PictureBox2 to overlay on PictureBox1. Make sure your PictureBox1 background is set to transparent. Then, you can programmatically set:

我知道这是一个古老的话题,但我想我会为那些寻找Windows Forms简单解决方案的人发布我想出的解决方案。假设你有PictureBox1和PictureBox2。您希望PictureBox2叠加在PictureBox1上。确保PictureBox1背景设置为透明。然后,您可以以编程方式设置:

PictureBox2.Parent = PictureBox1

Magic

#5


Transparent an Image, You can also used Adobe Photoshop to Remove White/Black Background (Watch Tutorial How to Create Transparent Background) or Use this code below,

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

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

#1


Depending on what you are trying to accomplish there's several different ways to go about it.

根据您要完成的任务,有几种不同的方法可以实现。

Some examples are -

一些例子是 -

Make bitmap transparent

使位图透明

Dim bmp As Bitmap = Bitmap.FromFile("test.bmp")
bmp.MakeTransparent(Color.Magenta) ' magenta in bitmap will be transparent
PictureBox1.Image = bmp

Make the picture box transparent

使图片框透明

PictureBox1.BackColor = Color.Transparent

If you really need a transparent image I would suggest not using the picturebox and just render a transparent bitmap directly.

如果你真的需要透明图像,我建议不要使用图片框,只是直接渲染透明位图。

#2


If you want the controls behind the PictureBox to show, ie. you want your image displayed with a transparent background, try drawing straight on the form itself.

如果你想要显示PictureBox背后的控件,即。如果希望图像以透明背景显示,请尝试直接在表单上绘图。

Back in the days of VB6 we could do this by hooking onto the Form's "Redraw" event or something...

回到VB6的时代,我们可以通过挂钩Form的“Redraw”事件或其他东西来做到这一点......

#3


On most controls in VB, in the Backcolor property of the object, there is an option for transparency. This works fine in VB2008, but in VB2005, you must then set it's .parent property to the object behind (well, in my experience anyways.)

在VB中的大多数控件中,在对象的Backcolor属性中,有一个透明选项。这在VB2008中工作正常,但是在VB2005中,你必须将它的.parent属性设置为后面的对象(好吧,根据我的经验)。

Hope this helps,

希望这可以帮助,

#4


I know this is an old topic, but I figured I'd post the solution I came up with for anyone looking for a simple solution for Windows Forms. Say you have PictureBox1 and PictureBox2. You want PictureBox2 to overlay on PictureBox1. Make sure your PictureBox1 background is set to transparent. Then, you can programmatically set:

我知道这是一个古老的话题,但我想我会为那些寻找Windows Forms简单解决方案的人发布我想出的解决方案。假设你有PictureBox1和PictureBox2。您希望PictureBox2叠加在PictureBox1上。确保PictureBox1背景设置为透明。然后,您可以以编程方式设置:

PictureBox2.Parent = PictureBox1

Magic

#5


Transparent an Image, You can also used Adobe Photoshop to Remove White/Black Background (Watch Tutorial How to Create Transparent Background) or Use this code below,

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

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