2013-02-21 100 views
0

Picture shaped窗體出現時,以下代碼不起作用。圖片不能正常工作

Dim Img As New System.Drawing.Bitmap(My.Resources.imgpng)'ImgPng is a resource Image 
    ' The color at Pixel(1,1) is rendered as transparent for the complete background. 
    Img.MakeTransparent(Img.GetPixel(1, 1)) 
    Me.BackgroundImage = Img 
    Me.TransparencyKey = Img.GetPixel(1, 1) 

任何人都可以幫助我更加接近嗎?

回答

0

感謝的人...

 Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
    Dim Img As New System.Drawing.Bitmap(My.Resources.NewImage) 'NewImage is a resource Image 
    ' The color at Pixel(1,1) is rendered as transparent for the complete background. 
    Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None 
    Dim Color = Img.GetPixel(0, 0) 
    Me.BackgroundImageLayout = ImageLayout.Stretch ' To Adjust the Image 
    Me.BackColor = Drawing.Color.Black 
    Img.MakeTransparent(Drawing.Color.Black) 
    Me.TransparencyKey = Drawing.Color.Black 
    Me.BackgroundImage = Img 
End Sub 

一變 'Img.MakeTransparent(色彩)' 不是必需的。嘗試getva正常的圖像與邊框輪廓,以消除不良邊緣...

+0

你爲什麼選擇這個作爲我的答案?好吧... – U1199880 2013-03-04 19:50:26

1

我通過這段代碼設置窗體背景相同,它的工作:

Dim Img As New System.Drawing.Bitmap(My.Resources.imgpng)'ImgPng is a resource Image 
' The color at Pixel(1,1) is rendered as transparent for the complete background. 
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None 
Dim Color = Img.GetPixel(0, 0) 
Me.BackColor = Color 
Img.MakeTransparent(Color) 
Me.TransparencyKey = Color 
Me.BackgroundImage = Img 

而且我用(0,0),用於透明像素雖然是不應該的問題,除非你的(1,1)是錯誤的顏色。

+0

(1,1)是圖像的第一個像素的顏色,(0,0)的作品,但你可以確認邊緣的質量? – SOAMad 2013-02-21 04:56:59

+0

這就是我用(1,1)希望獲得一些質量的原因。我相信另一種提高質量的方式可能是一個陰影效應。現在,當我給你一個代碼時,你可以幫我解決這個問題嗎?......並且謝謝你的迴應:)我會盡力使用這個回家! – SOAMad 2013-02-21 04:57:36

+0

我會建議爲陰影或其他效果制定另一個問題。 – U1199880 2013-02-21 14:11:52