StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
hanzy  
#1 Posted : Monday, August 23, 2021 1:11:29 AM(UTC)
hanzy

Rank: Member

Reputation:

Groups: Approved
Joined: 6/28/2019(UTC)
Posts: 15
China
Location: Southwest China

Thanks: 2 times
Was thanked: 1 time(s) in 1 post(s)
Hi Rob,

I don't know much coding, so I came for help.

Is S+ possible to pick the color of a pixel in hex color code ?

I tried searching the forum and got no good results (wrong keywords maybe?).

If affirmative, what's the script like?

Thanks for your generosity!
Rob  
#2 Posted : Monday, August 23, 2021 3:59:28 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,359
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 419 time(s) in 356 post(s)
Here's a script I use. Once started, it shows a text popup of the location and color as you move the mouse.
Once you click the left button, it copies the hex color code to the clipboard.

I have it show other info normally, but I commented those lines out - you can uncomment them if you'd like.

Code:
var currpt = sp.GetCurrentMousePoint();
var pxcolor = sp.GetPixelColorFromPoint(currpt);
var info = new DisplayTextInfo();
info.Message = "x: "+currpt.X+" y: " + currpt.Y+"\nRGB: "+pxcolor.R+"."+pxcolor.G+"."+pxcolor.B;
info.Duration = 1000;
info.MessageAlignment = "left";
info.Location = (currpt.X+10)+','+(currpt.Y-100); 
info.MessageFont = new Font("Segoe UI Semibold", 12);
info.BackColor = "black";
info.Padding = 0;
info.ClipToWorkingArea = false;
sp.DisplayText(info);
var chex = "";
while (!(sp.GetKeyState(vk.LBUTTON) & 0x8000)) {  
    currpt = sp.GetCurrentMousePoint();
    pxcolor = sp.GetPixelColorFromPoint(currpt);
    pxcolorAbove = sp.GetPixelColorFromPoint(new Point(currpt.X, currpt.Y - 100));
    var rhex = Number(pxcolor.R).toString(16);
    if (rhex.length < 2) {
         rhex = "0" + rhex;
    };
    var ghex = Number(pxcolor.G).toString(16);
    if (ghex.length < 2) {
         ghex = "0" + ghex;
    };
    var bhex = Number(pxcolor.B).toString(16);
    if (bhex.length < 2) {
         bhex = "0" + bhex;
    };
    var rhexAbove = Number(pxcolorAbove.R).toString(16);
    if (rhexAbove.length < 2) {
         rhexAbove = "0" + rhexAbove;
    };
    var ghexAbove = Number(pxcolorAbove.G).toString(16);
    if (ghexAbove.length < 2) {
         ghexAbove = "0" + ghex;
    };
    var bhexAbove = Number(pxcolorAbove.B).toString(16);
    if (bhexAbove.length < 2) {
         bhexAbove = "0" + bhex;
    };
    chex = "#" + rhex + ghex + bhex;
    info.Message = "x: "+currpt.X+" y: " + currpt.Y
    //info.Message += "\nAt Cursor - RGB: "+pxcolor.R+","+pxcolor.G+","+pxcolor.B;
    info.Message += "\nAt Cursor - hex: " + chex
    //info.Message += "\nAbove (100px) - RGB: "+pxcolorAbove.R+","+pxcolorAbove.G+","+pxcolorAbove.B; 
    //info.Message += "\nAbove (100px) - hex: #" + rhex + ghex + bhex; 
    info.Location = (currpt.X+10)+','+(currpt.Y-100); 
    sp.DisplayTextUpdate(info); //Refresh the existing text and location, instead of closing and reopening the popup
    sp.Sleep(10);
}
clip.SetText(chex);
sp.DisplayTextClose();
thanks 2 users thanked Rob for this useful post.
soooulp on 8/26/2021(UTC), asdf14 on 6/6/2022(UTC)
hanzy  
#3 Posted : Monday, August 23, 2021 5:00:20 PM(UTC)
hanzy

Rank: Member

Reputation:

Groups: Approved
Joined: 6/28/2019(UTC)
Posts: 15
China
Location: Southwest China

Thanks: 2 times
Was thanked: 1 time(s) in 1 post(s)
Thanks a lot!
randomConstant  
#4 Posted : Wednesday, August 25, 2021 9:00:11 PM(UTC)
randomConstant

Rank: Advanced Member

Reputation:

Groups: Translators, Approved
Joined: 7/17/2021(UTC)
Posts: 135

Thanks: 35 times
Was thanked: 18 time(s) in 15 post(s)
This is really helpful! Wish there was a way to view a zoomed in magnified view of the cursor to get accurate color but this is super helpful on its own.

Thanks Rob
Rob  
#5 Posted : Wednesday, August 25, 2021 11:29:32 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,359
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 419 time(s) in 356 post(s)
Could be modified to increase the font size and/or change the background color to match the point below the cursor....
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.