@@ -556,6 +556,18 @@ NAN_METHOD(setKeyboardDelay)
556
556
557
557
*/
558
558
559
+ /* *
560
+ * Pad hex color code with leading zeros.
561
+ * @param color Hex value to pad.
562
+ * @param hex Hex value to output.
563
+ */
564
+ void padHex (MMRGBHex color, char * hex)
565
+ {
566
+ // Length needs to be 7 because snprintf includes a terminating null.
567
+ // Use %06x to pad hex value with leading 0s.
568
+ snprintf (hex, 7 , " %06x" , color);
569
+ }
570
+
559
571
NAN_METHOD (getPixelColor)
560
572
{
561
573
MMBitmapRef bitmap;
@@ -567,12 +579,10 @@ NAN_METHOD(getPixelColor)
567
579
bitmap = copyMMBitmapFromDisplayInRect (MMRectMake (x, y, 1 , 1 ));
568
580
569
581
color = MMRGBHexAtPoint (bitmap, 0 , 0 );
570
-
571
- char hex [7 ];
572
-
573
- // Length needs to be 7 because snprintf includes a terminating null.
574
- // Use %06x to pad hex value with leading 0s.
575
- snprintf (hex, 7 , " %06x" , color);
582
+
583
+ char hex[7 ];
584
+
585
+ padHex (color, hex);
576
586
577
587
destroyMMBitmap (bitmap);
578
588
@@ -638,14 +648,14 @@ NAN_METHOD(getColor)
638
648
639
649
color = MMRGBHexAtPoint (bitmap, 300 , 300 );
640
650
641
- char hex [7 ];
642
651
643
- snprintf (hex, 7 , " %06x" , color);
644
652
645
653
printf (" 2: %s\n " , hex);
646
654
647
- // FIXME: Currently causes an error.
648
655
// destroyMMBitmap(bitmap);
656
+ char hex[7 ];
657
+
658
+ padHex (color, hex);
649
659
650
660
info.GetReturnValue ().Set (Nan::New (hex).ToLocalChecked ());
651
661
0 commit comments