@@ -135,13 +135,16 @@ private void UpdateTrayIcon()
135
135
bool global = config . sysProxyMode == ( int ) ProxyMode . Global ;
136
136
bool random = config . random ;
137
137
138
- Bitmap icon = null ;
139
138
try
140
139
{
141
- icon = new Bitmap ( "icon.png" ) ;
140
+ using ( Bitmap icon = new Bitmap ( "icon.png" ) )
141
+ {
142
+ _notifyIcon . Icon = Icon . FromHandle ( icon . GetHicon ( ) ) ;
143
+ }
142
144
}
143
145
catch
144
146
{
147
+ Bitmap icon = null ;
145
148
if ( dpi < 97 )
146
149
{
147
150
// dpi = 96;
@@ -171,8 +174,8 @@ private void UpdateTrayIcon()
171
174
mul_r = 0.4 ;
172
175
}
173
176
177
+ using ( Bitmap iconCopy = new Bitmap ( icon ) )
174
178
{
175
- Bitmap iconCopy = new Bitmap ( icon ) ;
176
179
for ( int x = 0 ; x < iconCopy . Width ; x ++ )
177
180
{
178
181
for ( int y = 0 ; y < iconCopy . Height ; y ++ )
@@ -185,10 +188,9 @@ private void UpdateTrayIcon()
185
188
( ( byte ) ( color . B * mul_b ) ) ) ) ;
186
189
}
187
190
}
188
- icon = iconCopy ;
191
+ _notifyIcon . Icon = Icon . FromHandle ( iconCopy . GetHicon ( ) ) ;
189
192
}
190
193
}
191
- _notifyIcon . Icon = Icon . FromHandle ( icon . GetHicon ( ) ) ;
192
194
193
195
// we want to show more details but notify icon title is limited to 63 characters
194
196
string text = ( enabled ?
@@ -857,20 +859,22 @@ private void Config_Click(object sender, EventArgs e)
857
859
858
860
private void Import_Click ( object sender , EventArgs e )
859
861
{
860
- OpenFileDialog dlg = new OpenFileDialog ( ) ;
861
- dlg . InitialDirectory = System . Windows . Forms . Application . StartupPath ;
862
- if ( dlg . ShowDialog ( ) == DialogResult . OK )
862
+ using ( OpenFileDialog dlg = new OpenFileDialog ( ) )
863
863
{
864
- string name = dlg . FileName ;
865
- Configuration cfg = Configuration . LoadFile ( name ) ;
866
- if ( cfg . configs . Count == 1 && cfg . configs [ 0 ] . server == Configuration . GetDefaultServer ( ) . server )
867
- {
868
- MessageBox . Show ( "Load config file failed" , "ShadowsocksR" ) ;
869
- }
870
- else
864
+ dlg . InitialDirectory = System . Windows . Forms . Application . StartupPath ;
865
+ if ( dlg . ShowDialog ( ) == DialogResult . OK )
871
866
{
872
- controller . MergeConfiguration ( cfg ) ;
873
- LoadCurrentConfiguration ( ) ;
867
+ string name = dlg . FileName ;
868
+ Configuration cfg = Configuration . LoadFile ( name ) ;
869
+ if ( cfg . configs . Count == 1 && cfg . configs [ 0 ] . server == Configuration . GetDefaultServer ( ) . server )
870
+ {
871
+ MessageBox . Show ( "Load config file failed" , "ShadowsocksR" ) ;
872
+ }
873
+ else
874
+ {
875
+ controller . MergeConfiguration ( cfg ) ;
876
+ LoadCurrentConfiguration ( ) ;
877
+ }
874
878
}
875
879
}
876
880
}
@@ -1169,32 +1173,33 @@ private void CopyAddress_Click(object sender, EventArgs e)
1169
1173
1170
1174
private bool ScanQRCode ( Screen screen , Bitmap fullImage , Rectangle cropRect , out string url , out Rectangle rect )
1171
1175
{
1172
- Bitmap target = new Bitmap ( cropRect . Width , cropRect . Height ) ;
1173
-
1174
- using ( Graphics g = Graphics . FromImage ( target ) )
1175
- {
1176
- g . DrawImage ( fullImage , new Rectangle ( 0 , 0 , cropRect . Width , cropRect . Height ) ,
1177
- cropRect ,
1178
- GraphicsUnit . Pixel ) ;
1179
- }
1180
- var source = new BitmapLuminanceSource ( target ) ;
1181
- var bitmap = new BinaryBitmap ( new HybridBinarizer ( source ) ) ;
1182
- QRCodeReader reader = new QRCodeReader ( ) ;
1183
- var result = reader . decode ( bitmap ) ;
1184
- if ( result != null )
1176
+ using ( Bitmap target = new Bitmap ( cropRect . Width , cropRect . Height ) )
1185
1177
{
1186
- url = result . Text ;
1187
- double minX = Int32 . MaxValue , minY = Int32 . MaxValue , maxX = 0 , maxY = 0 ;
1188
- foreach ( ResultPoint point in result . ResultPoints )
1178
+ using ( Graphics g = Graphics . FromImage ( target ) )
1179
+ {
1180
+ g . DrawImage ( fullImage , new Rectangle ( 0 , 0 , cropRect . Width , cropRect . Height ) ,
1181
+ cropRect ,
1182
+ GraphicsUnit . Pixel ) ;
1183
+ }
1184
+ var source = new BitmapLuminanceSource ( target ) ;
1185
+ var bitmap = new BinaryBitmap ( new HybridBinarizer ( source ) ) ;
1186
+ QRCodeReader reader = new QRCodeReader ( ) ;
1187
+ var result = reader . decode ( bitmap ) ;
1188
+ if ( result != null )
1189
1189
{
1190
- minX = Math . Min ( minX , point . X ) ;
1191
- minY = Math . Min ( minY , point . Y ) ;
1192
- maxX = Math . Max ( maxX , point . X ) ;
1193
- maxY = Math . Max ( maxY , point . Y ) ;
1190
+ url = result . Text ;
1191
+ double minX = Int32 . MaxValue , minY = Int32 . MaxValue , maxX = 0 , maxY = 0 ;
1192
+ foreach ( ResultPoint point in result . ResultPoints )
1193
+ {
1194
+ minX = Math . Min ( minX , point . X ) ;
1195
+ minY = Math . Min ( minY , point . Y ) ;
1196
+ maxX = Math . Max ( maxX , point . X ) ;
1197
+ maxY = Math . Max ( maxY , point . Y ) ;
1198
+ }
1199
+ //rect = new Rectangle((int)minX, (int)minY, (int)(maxX - minX), (int)(maxY - minY));
1200
+ rect = new Rectangle ( cropRect . Left + ( int ) minX , cropRect . Top + ( int ) minY , ( int ) ( maxX - minX ) , ( int ) ( maxY - minY ) ) ;
1201
+ return true ;
1194
1202
}
1195
- //rect = new Rectangle((int)minX, (int)minY, (int)(maxX - minX), (int)(maxY - minY));
1196
- rect = new Rectangle ( cropRect . Left + ( int ) minX , cropRect . Top + ( int ) minY , ( int ) ( maxX - minX ) , ( int ) ( maxY - minY ) ) ;
1197
- return true ;
1198
1203
}
1199
1204
url = "" ;
1200
1205
rect = new Rectangle ( ) ;
@@ -1203,32 +1208,33 @@ private bool ScanQRCode(Screen screen, Bitmap fullImage, Rectangle cropRect, out
1203
1208
1204
1209
private bool ScanQRCodeStretch ( Screen screen , Bitmap fullImage , Rectangle cropRect , double mul , out string url , out Rectangle rect )
1205
1210
{
1206
- Bitmap target = new Bitmap ( ( int ) ( cropRect . Width * mul ) , ( int ) ( cropRect . Height * mul ) ) ;
1207
-
1208
- using ( Graphics g = Graphics . FromImage ( target ) )
1211
+ using ( Bitmap target = new Bitmap ( ( int ) ( cropRect . Width * mul ) , ( int ) ( cropRect . Height * mul ) ) )
1209
1212
{
1210
- g . DrawImage ( fullImage , new Rectangle ( 0 , 0 , target . Width , target . Height ) ,
1211
- cropRect ,
1212
- GraphicsUnit . Pixel ) ;
1213
- }
1214
- var source = new BitmapLuminanceSource ( target ) ;
1215
- var bitmap = new BinaryBitmap ( new HybridBinarizer ( source ) ) ;
1216
- QRCodeReader reader = new QRCodeReader ( ) ;
1217
- var result = reader . decode ( bitmap ) ;
1218
- if ( result != null )
1219
- {
1220
- url = result . Text ;
1221
- double minX = Int32 . MaxValue , minY = Int32 . MaxValue , maxX = 0 , maxY = 0 ;
1222
- foreach ( ResultPoint point in result . ResultPoints )
1213
+ using ( Graphics g = Graphics . FromImage ( target ) )
1214
+ {
1215
+ g . DrawImage ( fullImage , new Rectangle ( 0 , 0 , target . Width , target . Height ) ,
1216
+ cropRect ,
1217
+ GraphicsUnit . Pixel ) ;
1218
+ }
1219
+ var source = new BitmapLuminanceSource ( target ) ;
1220
+ var bitmap = new BinaryBitmap ( new HybridBinarizer ( source ) ) ;
1221
+ QRCodeReader reader = new QRCodeReader ( ) ;
1222
+ var result = reader . decode ( bitmap ) ;
1223
+ if ( result != null )
1223
1224
{
1224
- minX = Math . Min ( minX , point . X ) ;
1225
- minY = Math . Min ( minY , point . Y ) ;
1226
- maxX = Math . Max ( maxX , point . X ) ;
1227
- maxY = Math . Max ( maxY , point . Y ) ;
1225
+ url = result . Text ;
1226
+ double minX = Int32 . MaxValue , minY = Int32 . MaxValue , maxX = 0 , maxY = 0 ;
1227
+ foreach ( ResultPoint point in result . ResultPoints )
1228
+ {
1229
+ minX = Math . Min ( minX , point . X ) ;
1230
+ minY = Math . Min ( minY , point . Y ) ;
1231
+ maxX = Math . Max ( maxX , point . X ) ;
1232
+ maxY = Math . Max ( maxY , point . Y ) ;
1233
+ }
1234
+ //rect = new Rectangle((int)minX, (int)minY, (int)(maxX - minX), (int)(maxY - minY));
1235
+ rect = new Rectangle ( cropRect . Left + ( int ) ( minX / mul ) , cropRect . Top + ( int ) ( minY / mul ) , ( int ) ( ( maxX - minX ) / mul ) , ( int ) ( ( maxY - minY ) / mul ) ) ;
1236
+ return true ;
1228
1237
}
1229
- //rect = new Rectangle((int)minX, (int)minY, (int)(maxX - minX), (int)(maxY - minY));
1230
- rect = new Rectangle ( cropRect . Left + ( int ) ( minX / mul ) , cropRect . Top + ( int ) ( minY / mul ) , ( int ) ( ( maxX - minX ) / mul ) , ( int ) ( ( maxY - minY ) / mul ) ) ;
1231
- return true ;
1232
1238
}
1233
1239
url = "" ;
1234
1240
rect = new Rectangle ( ) ;
0 commit comments