PixelGetColor能获取RGB24的数值吗?

遇到了问题?请先进行搜索(中文和英文),然后在此提问

Moderators: arcticir, tmplinshi

ddsspp
Posts: 2
Joined: 02 Nov 2019, 13:46

PixelGetColor能获取RGB24的数值吗?

04 Nov 2019, 09:47

怎么获取比较常见的RGB数值呢?
是否有函数能把RGB16转换到RGB24?
我想要获取屏幕像素的RGB24的数值还有HSV数值,怎么转换怎么获取?
fwejifjjwk2
Posts: 19
Joined: 10 Aug 2019, 01:49

Re: PixelGetColor能获取RGB24的数值吗?

04 Nov 2019, 21:50

第一個問題,網上一搜索就有了,PixelGetColor 可以獲得至少2種格式的 RGB,手冊和網上很容易找到。
RGB
https://autohotkey.com/board/topic/64390-getpixelcolor-how-to-separate-rgb-values/
Hexadecimal

link 被論壇擋住
http(://)fly530.blogspot.com/2010/06/autohotkey.html
第二個問題和第三個問題,都有現成的公式,很多參考代碼(別的語言的),寫完歡迎分享。
ddsspp
Posts: 2
Joined: 02 Nov 2019, 13:46

Re: PixelGetColor能获取RGB24的数值吗?

06 Nov 2019, 12:42

脚本作用类似PS的颜色取样器.
按下F3在鼠标的位置显示和刷新RGB和HSV数值.并且一只停留在按下F3位置.直到按下滚轮停止.
可以一边修改图像一边查看修改后的数值,不在需要把鼠标移动过去.PS在32位用脚本也能得到正确颜色并且PR和AE没有颜色取样器.

Code: Select all

#SingleInstance,Force   ;决定当脚本已经运行时是否允许它再次运行.  ;Force: 跳过对话框并自动替换旧实例, 效果类似于 Reload 命令.
add(x,y)
{
    return x+y
}

16bit0x_toRGB(HEX , to := "RGB") ;,  rgb := 0)
{
    ;第二个参数to可以是"RGB"或者"HSV".默认RGB
    R := Format("{:i}" ,"0x" SubStr(HEX, 3, 2))
    G := Format("{:i}" ,"0x" SubStr(HEX, 5, 2))
    B := Format("{:i}" ,"0x" SubStr(HEX, 7, 2))
    If (to = "RGB")
    {
        Return % "RGB:   " R "  " G "  " B
    }
    If (to = "HSV")
    {
        max:=max(R,G,B) ;
        min:=min(R,G,B) 
        if (R = max){
            H := (G-B)/(max-min) 
        }  
        if (G = max){
            H := 2 + (B-R)/(max-min)  
        }
        if (B = max){
            H := 4 + (R-G)/(max-min)
        }  
        H := Format("{:.0f}" , H := H * 60)
        if (H < 0){
            H := H + 360
        }
        ;计算方法来源 https www.cnblogs.com /Peit/p/7133244.html  Broken Link for safety
        V := Format("{:.0f}" , max(R,G,B)*100/255)
        S := Format("{:.0f}" , (max-min)*100/max)
        Return % "HSV:   " H "  " S "  " V   
    }

}
;方案4
f3::
CoordMode, Mouse
CoordMode, ToolTip
CoordMode, Pixel
MouseGetPos MouseX, MouseY
pianyi := 3 ;偏移量; 因为不能直接拾取鼠标正下面的像素.会拾取到上次结果颜色的对话"边框".....
MouseX_p := Add(MouseX, pianyi)
MouseY_p := Add(MouseY, pianyi)

Loop
{
    Sleep 80
    ;MouseGetPos MouseX, MouseY
    PixelGetColor, color, %MouseX%, %MouseY%, RGB
    color001 := 16bit0x_toRGB(color,"RGB")
    color002 := 16bit0x_toRGB(color,"HSV")
    ToolTip, %color001% `n%color002%, %MouseX_p%, %MouseY_p%
    if GetKeyState("MButton" , "p" )
    {
        ToolTip
        break  
    }
}
return

Return to “请求帮助”

Who is online

Users browsing this forum: No registered users and 13 guests