''' <summary> ''' 获取三切图指定序列 ''' </summary> ''' <param name="SourceBitmap">要切割的三切图源图</param> ''' <param name="nIndex">获取第几部分</param> ''' <returns></returns> ''' <res></res> Private Function GetnIndexBitmap(ByVal SourceBitmap As Bitmap, ByVal nIndex As Integer) As Bitmap Dim W As Integer = SourceBitmap.Width / 3 Dim H As Integer = SourceBitmap.Height Dim B As New Bitmap(W, H) Using G As Graphics = Graphics.FromImage(B) G.DrawImage(SourceBitmap, New Rectangle(0, 0, W, H), New Rectangle(SourceBitmap.Width / 3 * nIndex, 0, W, H), GraphicsUnit.Pixel) End Using Return B End Function'示例: Label1.BackgroundImage = GetnIndexBitmap(源图, 0) ' 普通状态 Label1.BackgroundImage = GetnIndexBitmap(源图, 1) ' 移上状态. Label1.BackgroundImage = GetnIndexBitmap(源图, 2) ' 按下状态
能在窗体显示这个图片的就行了
使用picbox加载图片ImageList[0],当鼠标移上去的时候加载ImageList[1];
我不用imagelist..用这个老是把图片弄的特难看。和原图不像。。我就是想问问。这样一张整个的图片。能不能实现。我说的那种效果!具体怎么实现呢?
''' 获取三切图指定序列
''' </summary>
''' <param name="SourceBitmap">要切割的三切图源图</param>
''' <param name="nIndex">获取第几部分</param>
''' <returns></returns>
''' <res></res>
Private Function GetnIndexBitmap(ByVal SourceBitmap As Bitmap, ByVal nIndex As Integer) As Bitmap
Dim W As Integer = SourceBitmap.Width / 3
Dim H As Integer = SourceBitmap.Height
Dim B As New Bitmap(W, H)
Using G As Graphics = Graphics.FromImage(B)
G.DrawImage(SourceBitmap, New Rectangle(0, 0, W, H), New Rectangle(SourceBitmap.Width / 3 * nIndex, 0, W, H), GraphicsUnit.Pixel)
End Using
Return B
End Function'示例:
Label1.BackgroundImage = GetnIndexBitmap(源图, 0) ' 普通状态
Label1.BackgroundImage = GetnIndexBitmap(源图, 1) ' 移上状态.
Label1.BackgroundImage = GetnIndexBitmap(源图, 2) ' 按下状态