由图片得到异形窗体

 

Public Class Form1

    Dim bmpBackground As Bitmap = Nothing

 

    Sub New()

        ' 此调用是Windows 窗体设计器所必需的。

        InitializeComponent()

 

        ' 在InitializeComponent() 调用之后添加任何初始化。

        FormBorderStyle = Windows.Forms.FormBorderStyle.None

    End Sub

 

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        SetBackgroundBitmap(Color.FromArgb(255, 0, 255))

    End Sub

 

    Protected Sub SetBackgroundBitmap(ByVal transparencyColor As Color)

        Me.bmpBackground = New Bitmap(MyClass.GetType(), "skin.bmp")

        Width = Me.bmpBackground.Width

        Height = Me.bmpBackground.Height

        Region = BitmapToRegion(Me.bmpBackground, transparencyColor)

    End Sub

 

    Protected Function BitmapToRegion(ByVal bitmap As Bitmap, ByVal transparencyColor As Color) As Region

        Dim height As Integer = bitmap.Height

        Dim width As Integer = bitmap.Width

        Dim path As New Drawing2D.GraphicsPath()

        Dim i As Integer

        Dim j As Integer

 

        For j = 0 To (height - 1)

            For i = 0 To (width - 1)

                If Not bitmap.GetPixel(i, j).Equals(transparencyColor) Then

                    Dim x0 As Integer = i

                    Do While ((i < width) AndAlso (Not bitmap.GetPixel(i, j).Equals(transparencyColor)))

                        i += 1

                    Loop

                    path.AddRectangle(New Rectangle(x0, j, i - x0, 1))

                End If

            Next

        Next

 

        Dim region As New Region(path)

        path.Dispose()

        Return region

    End Function

 

    Protected Overrides Sub OnPaintBackground(ByVal e As PaintEventArgs)

        Dim grfx As Graphics = e.Graphics

        grfx.PageUnit = GraphicsUnit.Pixel

        Dim offScreenGraphics As Graphics

        Dim offScreenBitmap As Bitmap

        offScreenBitmap = New Bitmap(Me.bmpBackground.Width, Me.bmpBackground.Height)

        offScreenGraphics = Graphics.FromImage(offScreenBitmap)

        If Not Me.bmpBackground Is Nothing Then

            offScreenGraphics.DrawImage(Me.bmpBackground, 0, 0, _

                                        Me.bmpBackground.Width, _

                                        Me.bmpBackground.Height)

        End If

        grfx.DrawImage(offScreenBitmap, 0, 0)

    End Sub

 

End Class

用到的 skin.bmp 你也可以自己找(应该看过的吧)

 

环境: Visual Studio2005
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值