Sign in to follow this  
Followers 0
November

Hex color to RGB and YMCK

5 posts in this topic

Hi there guys!!!

This is a new version of one of my posts :P

This was a request from a person from my job.

This is a little program tha captures the color from your desktop and convert it to RGB and YMCK format (and YMC too...).

There are a lot of free software for this, and this one is another free version :unsure:

I hope you like it and be usefull.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <Constants.au3>

Opt("TrayAutoPause",1)
Opt("TrayMenuMode",1)
        
HotKeySet("^!x" , "getcolor")
HotKeySet("{ESC}" , "fexit")

$setclip = 1

dim $vdif, $wdif, $output, $black, $cyanng, $magentang, $yellowng

$main = GUICreate("Get cursor Color", 75, 45, @DesktopWidth - 140, @DesktopHeight - 120, $WS_BORDER, $WS_EX_CLIENTEDGE + $WS_EX_TOPMOST )
GUISetState()

;Tray GUI Creation
$Clip = TrayCreateItem("To Clipboard ")
TrayItemSetState($clip, $TRAY_CHECKED)
$setclip = 1
TrayCreateItem("")
$valitem    = TrayCreateItem("Instructions")
TrayCreateItem("")
$aboutitem  = TrayCreateItem("About")
TrayCreateItem("")
$exit = TrayCreateItem("Exit")
TraySetState()

While 1
    $mouse = MouseGetPos()
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            $var = PixelGetColor( $mouse[0] , $mouse[1])
            $background = GUICtrlSetBkColor($main, $var)
            GUISetBkColor($var, $main)
            ContinueLoop
        Case $msg = $Clip
            $decide = TrayItemGetState($clip)
            If $decide = 1 then 
                $setclip = 1
            Else
                $setclip = 0
            endif
        Case $msg = $valitem
            Msgbox(64,"Instructions:","ALT+CTRL+X - Get Color" & @CRLF & "ESC - Exit Program")
        Case $msg = $aboutitem
            Msgbox(64,"About:","November 2009" & @CRLF & "Free usage")
        Case $msg = $exit
            exit
    EndSelect
WEnd

Func getcolor()
    
;Hex color to RGB
    $output = ""
    $hex = Hex ( $var , 6)
    $HR = StringMid($hex, 1, 2)
    $HG = StringMid($hex, 3, 2)
    $HB = StringMid($hex, 5, 2)
    $R = Dec($HR)
    $G = Dec($HG)
    $B = Dec($HB)
    
;Convert RGB to CMY
    $cyanr = 1-($r/255)
    $magentar = 1-($g/255)
    $yellowr= 1-($b/255)
    
;Convert CMY to CMYK
    $blackr=1

    If $blackr > $cyanr Then $blackr = $cyanr
    if $blackr > $magentar Then $blackr= $magentar
    if $blackr > $yellowr Then $blackr = $yellowr
    if $blackr = 1 Then
        $cyanr = 0
        $magentar = 0
        $yellowr = 0
    Else
        $cyanr = ($cyanr-$blackr)/(1-$blackr)
        $magentar = ($magentar-$blackr)/(1-$blackr)
        $yellowr = ($yellowr-$blackr)/(1-$blackr)
    EndIf
    $kr = $blackr
        
;Let's get only the three decimal numbert to match YMCK requirements    
    $cyan = StringFormat("%.3f", $cyanr)
    $magenta = StringFormat("%.3f", $magentar)
    $yellow = StringFormat("%.3f", $yellowr)
    $k = StringFormat("%.3f", $kr)
    
;Output results in a a ballon or to the clipboard
    $output = "Hexadecimal : " & $hex & @CRLF
    $output = $output & "RGB : " & $R & ", " & $G & ", " & $B & @CRLF
    $output = $output & "CYMK : C-" & $cyan & ", M-" & $magenta & ", Y-" &  $yellow & ", K-" & $k
    TrayTip("RGB / CYMK Color", $output, 1)
    $backup = ClipGet()
    If $setclip = 1 then 
        ClipPut($output)
    Else
        ClipPut($backup)
    EndIf

EndFunc

func fexit()
    Exit
EndFunc

Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Share this post


Link to post
Share on other sites



Good idea, but less than the CMYK color space than RGB. Here it is necessary to use a profile for the printing device and the parameters of color separation. For this purpose, better to use Photoshop.

But the learning good example.

:P

Share this post


Link to post
Share on other sites
thank you for sharing this one bro!! i know u did a hardwork... u get ten thumbs from me:D

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Simpler method to get RGB.

$Hex = 0xAABBCC
$R = BitShift(BitAND($Hex,0xFF0000),16)
$G = BitShift(BitAND($Hex, 0xFF00),8)
$B = BitAND($Hex, 0xFF)

MsgBox(0,"","Hex: " & $Hex & @CRLF & _
        "R: " & $R & @CRLF & _
        "G: " & $G & @CRLF & _
        "B: " & $B)

also defined in Color.au3 under functions _ColorGetX. X can be Red, Green or Blue. Very fast.

Edited by Manadar

Share this post


Link to post
Share on other sites

Simpler method to get RGB.

$Hex = 0xAABBCC
$R = BitShift(BitAND($Hex,0xFF0000),16)
$G = BitShift(BitAND($Hex, 0xFF00),8)
$B = BitAND($Hex, 0xFF)

MsgBox(0,"","Hex: " & $Hex & @CRLF & _
        "R: " & $R & @CRLF & _
        "G: " & $G & @CRLF & _
        "B: " & $B)

also defined in Color.au3 under functions _ColorGetX. X can be Red, Green or Blue. Very fast.

Ok Manadar... thanks for the useful tips.

I'll get it a try and see if the script performance get better.

Cheers


Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0