【发布时间】:2015-07-22 15:11:38
【问题描述】:
我想为 visual basic 6 程序的背景设置透明的红色。
我使用这段代码使表单的背景透明:
Option Explicit
Private Const GWL_EXSTYLE As Long = (-20)
Private Const LWA_COLORKEY As Long = &H1
Private Const LWA_Defaut As Long = &H2
Private Const WS_EX_LAYERED As Long = &H80000
Private Declare Function GetWindowLong Lib "user32" Alias _
"GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias _
"SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32" _
(ByVal hWnd As Long, ByVal crKey As Long, ByVal bDefaut As Byte, _
ByVal dwFlags As Long) As Long
Private Sub Form_Load()
Me.BackColor = RGB(254,0,0)
Transparency Me.hWnd, Me.BackColor, 255
End Sub
Private Sub Transparency(ByVal hWnd As Long, ByVal lngTransparentColor As Long, _
ByVal bytTransparency As Byte)
Dim lngwindowstyle As Long
lngwindowstyle = GetWindowLong(hWnd, GWL_EXSTYLE)
If (lngwindowstyle And WS_EX_LAYERED) <> WS_EX_LAYERED Then
SetWindowLong hWnd, GWL_EXSTYLE, lngwindowstyle Or WS_EX_LAYERED
End If
SetLayeredWindowAttributes hWnd, lngTransparentColor, bytTransparency, _
LWA_COLORKEY Or LWA_Defaut
End Sub
但正如您在图片中看到的,红色噪点仍然存在:
如何消除这种噪音?
我保存了带有.png扩展名的图片并使用AlphaImageControl.ocx显示它。
红噪声被移除,但表格下方的红线仍然存在:
【问题讨论】:
-
你的代码没问题。您的表单上是否有分配给表单的
Picture属性或其他一些Image或PictureBox的图片导致“额外”红色? -
我在 Form 的
Picture属性中有一张图片,没有Image没有PictureBox -
透明色与 RGB 值完全匹配。您的图片中有一些像素不完全是 RGB 254, 0, 0,而是另一种红色阴影。任何要透明的像素都必须完全是那种颜色。在图像编辑器中编辑图片。
-
您不能使用此效果进行抗锯齿。如果您的图片具有除 RGB(254,0,0) 以外的任何其他红色值,它就会出现。
-
我希望它仍然是同样的问题。我希望这些像素不完全是 RGB 254, 0, 0
标签: winforms vb6 transparency rgb