@@ -39,6 +39,7 @@ public Color SelectedColor
39
39
set
40
40
{
41
41
tmp_selectedcolor = value ;
42
+ UpdateColorPickerFromColor ( value ) ;
42
43
ColorChanged ( value ) ;
43
44
}
44
45
}
@@ -236,8 +237,9 @@ private Color PickColor(float x, float y)
236
237
return Color . Empty ;
237
238
}
238
239
239
- label1 . Text = $ "RGB: { Color . R } , { Color . G } , { Color . B } ";
240
240
label2 . Text = $ "HEX: #{ Color . ToArgb ( ) : X} ";
241
+ label1 . Text = $ "RGB: { Color . R } , { Color . G } , { Color . B } ";
242
+
241
243
CursorPos = new PointF ( x1 + ( ( float ) pictureBox1 . Width / 2 ) , y1 + ( ( float ) pictureBox1 . Height / 2 ) ) ;
242
244
pictureBox2 . BackColor = Color ;
243
245
( ( ValueBox ) pictureBox3 . Tag ) . Color = Color ;
@@ -316,6 +318,70 @@ private Color HSVtoRGB(double H, double S, double V)
316
318
return Color . FromArgb ( ( int ) R , ( int ) G , ( int ) B ) ;
317
319
}
318
320
321
+ private void UpdateColorPickerFromColor ( Color color )
322
+ {
323
+ if ( color . IsEmpty || color == Color . Transparent )
324
+ {
325
+ return ;
326
+ }
327
+
328
+ RGBtoHSV ( color . R , color . G , color . B , out double h , out double s , out double v ) ;
329
+
330
+ float radius = ( float ) pictureBox1 . Width / 2 ;
331
+ float saturationRadius = ( float ) ( s * radius ) ;
332
+ double angleRad = h * 2 * Math . PI ;
333
+
334
+ float x = ( float ) ( saturationRadius * Math . Cos ( angleRad ) ) + radius ;
335
+ float y = ( float ) ( saturationRadius * Math . Sin ( angleRad ) ) + radius ;
336
+
337
+ ( ( ValueBox ) pictureBox3 . Tag ) . Value = ( float ) v ;
338
+ ( ( ValueBox ) pictureBox3 . Tag ) . Color = HSVtoRGB ( h , s , 1.0 ) ;
339
+
340
+ CursorPos = new PointF ( x , y ) ;
341
+ pictureBox1 . Tag = new PointF ( x , y ) ;
342
+
343
+ label1 . Text = $ "RGB: { color . R } , { color . G } , { color . B } ";
344
+ label2 . Text = $ "HEX: #{ color . ToArgb ( ) : X} ";
345
+ pictureBox2 . BackColor = color ;
346
+
347
+ pictureBox1 . Invalidate ( ) ;
348
+ pictureBox2 . Invalidate ( ) ;
349
+ pictureBox3 . Invalidate ( ) ;
350
+ }
351
+
352
+ private void RGBtoHSV ( int r , int g , int b , out double h , out double s , out double v )
353
+ {
354
+ double red = r / 255.0 ;
355
+ double green = g / 255.0 ;
356
+ double blue = b / 255.0 ;
357
+
358
+ double max = Math . Max ( red , Math . Max ( green , blue ) ) ;
359
+ double min = Math . Min ( red , Math . Min ( green , blue ) ) ;
360
+ double delta = max - min ;
361
+
362
+ v = max ;
363
+
364
+ s = max == 0 ? 0 : delta / max ;
365
+
366
+ h = 0 ;
367
+ if ( delta != 0 )
368
+ {
369
+ if ( max == red )
370
+ {
371
+ h = ( ( green - blue ) / delta ) + ( green < blue ? 6 : 0 ) ;
372
+ }
373
+ else if ( max == green )
374
+ {
375
+ h = ( ( blue - red ) / delta ) + 2 ;
376
+ }
377
+ else
378
+ {
379
+ h = ( ( red - green ) / delta ) + 4 ;
380
+ }
381
+ h /= 6 ;
382
+ }
383
+ }
384
+
319
385
#endregion
320
386
}
321
387
0 commit comments