DSAPI 3张图片实现花开动画
效果图
素材
代码
Dim B0, B1, B3 As Bitmap Private B As Bitmap = Nothing Private Sub Loading_Load(sender As Object, e As EventArgs) Handles MyBase.Load B0 = My.Resources.P0.Clone B1 = My.Resources.P1.Clone B3 = My.Resources.P3.Clone Me.Show() End Sub Private Sub Play() For I As Single = 0.1 To 1.5 Step 0.02 If Me.Disposing Then Exit Sub MakeBg(I) Threading.Thread.Sleep(10) Application.DoEvents() Next MakeBg(1.5) Threading.Thread.Sleep(2000) For I As Single = 255 To 0 Step -1 If Me.Disposing Then Exit Sub DSAPI.控件.Form窗体.透明窗体样式显示图像(Me, B, I) Application.DoEvents() Next End Sub Private Sub MakeBg(Db As Single) Try If B IsNot Nothing Then B.Dispose() B = Nothing If Db < 1.5 Then B = B0.Clone Using G As Graphics = Graphics.FromImage(B) G.Clip = New Region(New Rectangle(0, 0, 625, 656)) Dim _B1 As Bitmap = New Bitmap(625, 656) Using G2 As Graphics = Graphics.FromImage(_B1) G2.Clip = New Region(New RectangleF(0, 0, 625, 656)) Dim W, H As Integer Dim _B As Bitmap = MakeImg(Db) W = (625 - _B.Width) / 2 H = (656 - _B.Height) / 2 G2.DrawImage(_B, New Rectangle(W, H, _B.Width, _B.Height), New Rectangle(0, 0, _B.Width, _B.Height), GraphicsUnit.Pixel) _B.Dispose() End Using Dim _B3 As Bitmap = B1.Clone DSAPI.图形图像.应用透明度遮罩(_B3, _B1) _B1.Dispose() G.DrawImage(_B3, New Rectangle(0, 0, 625, 656), New Rectangle(0, 0, 625, 656), GraphicsUnit.Pixel) End Using Else B = B1.Clone End If DSAPI.控件.Form窗体.透明窗体样式显示图像(Me, B, 255) Catch End Try End Sub Private Sub Loading_Shown(sender As Object, e As EventArgs) Handles Me.Shown For I As Single = 0 To 255 DSAPI.控件.Form窗体.透明窗体样式显示图像(Me, B0, I) Application.DoEvents() If Me.Opacity = 0 Then Me.Opacity = 1 Next Play() Me.Close() End Sub Private Function MakeImg(Db As Single) As Bitmap Try Dim W, H As Integer W = 410 * Db H = 431 * Db Dim BB As New Bitmap(W, H) Using G As Graphics = Graphics.FromImage(BB) G.Clip = New Region(New Rectangle(0, 0, W, H)) G.DrawImage(B3, New Rectangle(0, 0, W, H), New Rectangle(0, 0, 410, 431), GraphicsUnit.Pixel) End Using Return BB Catch Return Nothing End Try End Function
原理:
1 缩放黑影大小,并绘制到和花图一样的图片上
2 使用黑影图作为花图的透明度遮罩,有黑影的地方不透明,其他地方透明
3 将花图绘制到灰白的花上