2020年5月19日 星期二

vb.net picturebox的圖片淡出與淡入的特效 [Picturebox Fade in Fade out effect]


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
Private m_Alpha As Single = 0 ' Alpha on a 0-1 scale.

Private m_DAlpha As Single = 0.05


Private Sub tmrDisplayFrame_Tick(ByVal sender As _

    System.Object, ByVal e As System.EventArgs) Handles _

    tmrDisplayFrame.Tick

    Dim bm1 As Bitmap = picSrc1.Image.Clone

    Dim bm2 As Bitmap = picSrc2.Image.Clone


    Dim image_attr As New ImageAttributes

    Dim cm As ColorMatrix



    Dim bm As New Bitmap(bm1.Width, bm1.Height)

    Dim gr As Graphics = Graphics.FromImage(bm)

    Dim rect As Rectangle = _

        Rectangle.Round(bm1.GetBounds(GraphicsUnit.Pixel))


    cm = New ColorMatrix(New Single()() { _

        New Single() {1.0, 0.0, 0.0, 0.0, 0.0}, _

        New Single() {0.0, 1.0, 0.0, 0.0, 0.0}, _

        New Single() {0.0, 0.0, 1.0, 0.0, 0.0}, _

        New Single() {0.0, 0.0, 0.0, 0.0, 0.0}, _

        New Single() {0.0, 0.0, 0.0, m_Alpha, 1.0}})

    image_attr.SetColorMatrix(cm)

    gr.DrawImage(bm1, rect, 0, 0, bm1.Width, bm2.Width, _

        GraphicsUnit.Pixel, image_attr)


    cm = New ColorMatrix(New Single()() { _

        New Single() {1.0, 0.0, 0.0, 0.0, 0.0}, _

        New Single() {0.0, 1.0, 0.0, 0.0, 0.0}, _

        New Single() {0.0, 0.0, 1.0, 0.0, 0.0}, _

        New Single() {0.0, 0.0, 0.0, 0.0, 0.0}, _

        New Single() {0.0, 0.0, 0.0, 1 - m_Alpha, 1.0}})

    image_attr.SetColorMatrix(cm)

    gr.DrawImage(bm2, rect, 0, 0, bm1.Width, bm2.Width, _

        GraphicsUnit.Pixel, image_attr)


    picResult.Image = bm

    picResult.Refresh()


    m_Alpha += m_DAlpha

    If m_Alpha > 1 Then

        m_Alpha = 1

        m_DAlpha *= -1

    ElseIf m_Alpha < 0 Then

        m_Alpha = 0

        m_DAlpha *= -1

    End If

End Sub

沒有留言:

張貼留言