PNG圖片本身設(shè)置通道,使用Adobe Photoshop加入這個通道這樣就肯定沒白邊了
專業(yè)成都網(wǎng)站建設(shè)公司,做排名好的好網(wǎng)站,排在同行前面,為您帶來客戶和效益!創(chuàng)新互聯(lián)為您提供成都網(wǎng)站建設(shè),五站合一網(wǎng)站設(shè)計制作,服務(wù)好的網(wǎng)站設(shè)計公司,成都網(wǎng)站設(shè)計、成都網(wǎng)站制作負責(zé)任的成都網(wǎng)站制作公司!
這方面的知識屬于Photoshop繪圖相關(guān)的
通道的意思就是為這個時鐘設(shè)置一個選擇范圍蒙板,屏蔽除時鐘這個大圓形外的其它部分
加入通道后,把時鐘外其它部分圖像填充藍色
這方面還有一些專用的技巧的,如通道設(shè)置的這個圓形范圍周圍做模糊處理之類的,說起來很復(fù)雜你也看不明白。你網(wǎng)上找一下有沒有Photoshop加入通道演示的內(nèi)容吧
這種功能讀winform來說只有容器才能設(shè)置透明度,如form、panel類控件,其他的不是不可以,要重寫背景參數(shù),而且重寫完了后與win7、Xp互不兼容,閃爍,并不提倡。.net的解決辦法是wpf,控件可以設(shè)置opation屬性,靈活控制透明度,并且后臺靜態(tài)刷新,因為他是xaml機制構(gòu)造。
將窗體的transparencykey屬性設(shè)置為與窗體的backcolor屬性相同,看看是不是你要的效果。
窗體透明,控件不透明的代碼:
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 bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Const WS_EX_LAYERED = H80000
Private Const GWL_EXSTYLE = (-20)
Private Const LWA_ALPHA = H2
Private Const LWA_COLORKEY = H1
Private Sub Form_Load()
Me.BackColor = HFF0000
Dim rtn As Long
Dim BorderStyler
BorderStyler = 0
rtn = GetWindowLong(hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes hwnd, HFF0000, 0, LWA_COLORKEY
End Sub
窗體逐漸變透明:
'添加一個PicturebBox,依它為容器添加一個shape,背景色設(shè)為藍色
'添加一個時鐘控件
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 bAlpha As Byte, ByVal dwFlags As Long) As Long
Const WS_EX_LAYERED = H80000
Const GWL_EXSTYLE = (-20)
Const LWA_ALPHA = H2
Const LWA_COLORKEY = H1
Dim tmd As Long
Private Sub Form_Load()
Show
Shape1.BackColor = H80000002
Shape1.BackStyle = 1
tmd = 255
Timer1.Interval = 50
Shape1.Width = Picture1.Width
SetWindowLong hwnd, GWL_EXSTYLE, WS_EX_LAYERED
SetLayeredWindowAttributes hwnd, 0, tmd, LWA_ALPHA '越少越透明,限制0-255
End Sub
Private Sub Timer1_Timer()
On Error Resume Next
tmd = tmd - 1
SetLayeredWindowAttributes hwnd, 0, tmd, LWA_ALPHA
Shape1.Width = Shape1.Width - Picture1.Width / 255
If tmd 0 Then
Timer1.Enabled = False
MsgBox "OK!"
End If
End Sub
簡單的部分透明比較難做,不過可以換個方式考慮一下。
把本問題轉(zhuǎn)換成在VB.NET 2005環(huán)境下創(chuàng)建不規(guī)則窗體(=普通窗體 - 透明部分)問題,解決方法就很多了,網(wǎng)上也有許多例子。如 章立民 的書里就詳細講過。
大致思路如下:
1。將backgroundimage設(shè)成一個位圖(點陣圖)
2.將Transparaencykey設(shè)成位圖的背景顏色(位圖最取背景單純,單純部分將成為透明部分)
3.如需要可以將formborderstyle設(shè)為none,會移除標(biāo)題欄,并需要手動編寫窗體移動、關(guān)閉等動作代碼,
Option Explicit
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, _
ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, _
ByVal hObject As Long) As Long
Private Sub Form_Load()
Form1.BorderStyle = 0
Dim Bitmap
Me.AutoRedraw = True
Bitmap = CreateCompatibleBitmap(Me.hdc, 0, 0)
SelectObject Me.hdc, Bitmap '設(shè)置窗體透明
End Sub
Private Sub Form_Click()
End '單擊窗體任何地方都是退出程序
End Sub
自己寫的一段代碼。你看一下吧。。我寫是完全的。直接沒有了標(biāo)題欄,如果想要標(biāo)題欄的話。把其中的 Form1.BorderStyle = 0 這句去掉就可以了。