1+ using System ;
2+ using System . Drawing ;
3+ using System . Drawing . Imaging ;
4+ using System . IO ;
5+
6+ namespace BitLockerManager
7+ {
8+ public static class IconHelper
9+ {
10+ public static Icon CreateIconFromPng ( string pngPath )
11+ {
12+ try
13+ {
14+ // Try to load ICO file first (better quality)
15+ var icoPath = pngPath . Replace ( ".png" , ".ico" ) ;
16+ if ( File . Exists ( icoPath ) )
17+ {
18+ return new Icon ( icoPath ) ;
19+ }
20+
21+ // Fallback to PNG
22+ if ( File . Exists ( pngPath ) )
23+ {
24+ using ( var bitmap = new Bitmap ( pngPath ) )
25+ {
26+ // Create a 32x32 version for the icon
27+ using ( var resized = new Bitmap ( bitmap , 32 , 32 ) )
28+ {
29+ return Icon . FromHandle ( resized . GetHicon ( ) ) ;
30+ }
31+ }
32+ }
33+ else
34+ {
35+ return CreateFallbackIcon ( ) ;
36+ }
37+ }
38+ catch
39+ {
40+ return CreateFallbackIcon ( ) ;
41+ }
42+ }
43+
44+ public static Icon CreateFallbackIcon ( )
45+ {
46+ var bitmap = new Bitmap ( 32 , 32 ) ;
47+ using ( var g = Graphics . FromImage ( bitmap ) )
48+ {
49+ g . Clear ( Color . Transparent ) ;
50+ g . SmoothingMode = System . Drawing . Drawing2D . SmoothingMode . AntiAlias ;
51+
52+ // Create a BitLocker-style shield icon
53+ using ( var blueBrush = new SolidBrush ( Color . FromArgb ( 0 , 120 , 215 ) ) )
54+ using ( var whiteBrush = new SolidBrush ( Color . White ) )
55+ using ( var darkBrush = new SolidBrush ( Color . FromArgb ( 0 , 90 , 180 ) ) )
56+ {
57+ // Draw shield background
58+ var shieldPoints = new Point [ ]
59+ {
60+ new Point ( 16 , 3 ) ,
61+ new Point ( 27 , 9 ) ,
62+ new Point ( 27 , 19 ) ,
63+ new Point ( 16 , 29 ) ,
64+ new Point ( 5 , 19 ) ,
65+ new Point ( 5 , 9 )
66+ } ;
67+
68+ g . FillPolygon ( blueBrush , shieldPoints ) ;
69+
70+ // Draw lock symbol
71+ // Lock body
72+ g . FillRectangle ( whiteBrush , 11 , 17 , 10 , 8 ) ;
73+ g . DrawRectangle ( Pens . Black , 11 , 17 , 10 , 8 ) ;
74+
75+ // Lock shackle
76+ using ( var pen = new Pen ( Color . Black , 2 ) )
77+ {
78+ g . DrawArc ( pen , 13 , 11 , 6 , 8 , 0 , 180 ) ;
79+ }
80+
81+ // Lock keyhole
82+ g . FillEllipse ( Brushes . Black , 15 , 20 , 2 , 2 ) ;
83+ }
84+ }
85+
86+ return Icon . FromHandle ( bitmap . GetHicon ( ) ) ;
87+ }
88+ }
89+ }
0 commit comments