forked from lee-soft/ViStart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AlphaIcon.cls
105 lines (76 loc) · 2.53 KB
/
AlphaIcon.cls
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "AlphaIcon"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Private m_Icon As GDIPBitmap
Private m_IconXP As GDIPBitmap
Private m_IsAlphaBitmap As Boolean
Private m_logger As SeverityLogger
Property Get Logger() As SeverityLogger
Set Logger = m_logger
End Property
Public Property Get Image() As GDIPImage
Set Image = m_IconXP.Image
End Property
Public Function CreateFromHICON(ByVal icoHandle As Long)
Dim ii As ICONINFO
Dim bmData As BitmapData
Dim bmBounds As gdiplus.RECTL
Dim X As Long
Dim Y As Long
Set m_Icon = New GDIPBitmap
Set m_IconXP = New GDIPBitmap
If GetIconInfo(icoHandle, ii) = 0 Then
Logger.Error "Error retrieving icon info!", "CreateFromHICON"
End If
m_Icon.CreateFromHBITMAP ii.hbmColor, 0
DeleteObject ii.hbmColor
DeleteObject ii.hbmMask
If m_Icon.Image.ImgPixelFormat = PixelFormat.Format32bppArgb Then
End If
'If BITMAP.GetPixelFormatSize(m_Icon.PixelFormat) < 32 Then
'Return ico.ToBitmap
'End If
bmBounds.Width = m_Icon.Image.Width
bmBounds.Height = m_Icon.Image.Height
bmData = m_Icon.LockBits(bmBounds, _
ImageLockModeRead, _
m_Icon.Image.ImgPixelFormat)
m_IconXP.CreateFromSizeFormatData bmData.Height, _
bmData.Width, _
bmData.stride, _
Format32bppArgb, _
bmData.Scan0Ptr
m_IsAlphaBitmap = False
For Y = 0 To bmData.Height - 1
For X = 0 To bmData.Width - 1
Dim PixelColor As ARGB
Long2ARGB m_IconXP.GetPixel(X, Y), PixelColor
'PixelColor = Color.FromArgb(Marshal.ReadInt32(bmData.Scan0, (bmData.Stride * y) + (4 * x)))
If PixelColor.A > 0 And PixelColor.A < 255 Then
m_IsAlphaBitmap = True
Exit For
End If
Next
If m_IsAlphaBitmap Then Exit For
Next
m_Icon.UnlockBits bmData
If Not m_IsAlphaBitmap Then
m_Icon.Dispose
m_IconXP.Dispose
m_IconXP.CreateFromHICON icoHandle
End If
End Function
Private Sub Class_Initialize()
Set m_logger = LogManager.GetCurrentClassLogger(Me)
End Sub