![]() |
|
find color of a pixel - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10) +---- Thread: find color of a pixel (/showthread.php?tid=3986) |
find color of a pixel - PhilOfPerth - 10-09-2025 I need to identify and use the colour of a pixel on my screen. I have written the code as attached, which tells me the RGB values, but I can't work out how to apply this to another area. I'm sure it's something simple but so am I. Any help appreciated .Code: (Select All) SW = 1040: SH = 750RE: find color of a pixel - ahenry3068 - 10-09-2025 (10-09-2025, 07:15 AM)PhilOfPerth Wrote: I need to identify and use the colour of a pixel on my screen. I have written the code as attached, which tells me the RGB values, but I can't work out how to apply this to another area. I'm sure it's something simple but so am I. Any help appreciatedWhen you say "Apply to another Area" . are you asking how to set another Pixel to this color ? If so then the easiest way would be PSET. RE: find color of a pixel - PhilOfPerth - 10-09-2025 (10-09-2025, 07:20 AM)ahenry3068 Wrote:(10-09-2025, 07:15 AM)PhilOfPerth Wrote: I need to identify and use the colour of a pixel on my screen. I have written the code as attached, which tells me the RGB values, but I can't work out how to apply this to another area. I'm sure it's something simple but so am I. Any help appreciatedWhen you say "Apply to another Area" . are you asking how to set another Pixel to this color ? If so then the easiest way would be PSET. Thanks ahenry. Yes, that's what I want to do, I just can't find the syntax for doing it. Something like PSet(400,400), ThisColor maybe, with ThisColor set as a Long integer? (that doesn't work though).. RE: find color of a pixel - SMcNeill - 10-09-2025 Code: (Select All)
RE: find color of a pixel - SMcNeill - 10-09-2025 https://qb64phoenix.com/qb64wiki/index.php/RGB32 <-- That's the command you're looking for. *But also look close at the comments about variable type and run the demo above to see what I'm talking about.* RE: find color of a pixel - PhilOfPerth - 10-09-2025 Thanks Steve. I struggled to understand that - more a function of my ability than the quality of the examples I'm afraid - but finally came up with thiis: Code: (Select All) SW = 1040: SH = 750RE: find color of a pixel - SMcNeill - 10-09-2025 (10-09-2025, 08:44 AM)PhilOfPerth Wrote: Thanks Steve. You didn't look at what I posted in the demo prior to this. Your issue is, once again, *VARIABLE TYPE*. You are not dimming pixclr as an _UNSIGNED LONG, which is needed when working with 32-bit colors. It's defaulting to SINGLE variable type, which lacks precision to hold the higher values of your colors. Once you DIM pixclr AS _UNSIGNED LONG, you won't have as many issues making use of it. Quote:But how do I use this in a Color _RGB(r,g.b), _RGB(r,g,b) format? It doesn't allow _RGB(r,g,b),(pixclr) Didn't you just make use of it in both ways in your own code above?? Code: (Select All)
That first statement uses _RGB(red, green, blue) values to set the color. The second statement uses a variable to set the color. Isn't that what you just asked? How to use it in a color statement? COLOR _RGB(255, 255, 255), pixclr '<--- This would set a foreground color of white (as you point out in your own code), and a background color of whatever the variable pixclr contains. If you're asking about the PSET statement itself, the usage is just as simple as those two color commands which you've typed into your code above: Code: (Select All)
You've successfully made use of _RGB in your code posted. You've successfully made use of a variable holding the color value. I really don't see what you're not getting here. The only problem I see is you're not making your variable the proper type to work with 32-bit colors. SINGLE won't hold the values for 32-bit colors. You want to use _UNSIGNED LONG variable types instead. Otherwise.... just use _RGB(red, green, blue) for your constant colors as you have been, and pixclr as your variable which holds those same values. You've used both properly in your own code above. What are you missing here? Where's the AHA lightbulb moment you're looking for? RE: find color of a pixel - Dimster - 10-09-2025 Hi Phil, I was looking at the wiki and Point(x,y) seems to be able to capture the color of a pixel at (x,y) so PixelColor = Point(x,y) from there I believe the directions would be to break out each individual red, green, blue ie R=_Red32(PixelColor) etc. Boy I could be so far out to lunch on this, I have often miss read the directions in the wiki and have never used Point before. RE: find color of a pixel - SMcNeill - 10-09-2025 (10-09-2025, 04:38 PM)Dimster Wrote: Hi Phil, I was looking at the wiki and Point(x,y) seems to be able to capture the color of a pixel at (x,y) so PixelColor = Point(x,y) from there I believe the directions would be to break out each individual red, green, blue ie R=_Red32(PixelColor) etc. Boy I could be so far out to lunch on this, I have often miss read the directions in the wiki and have never used Point before. If you just want to copy the color and use it elsewhere, it's as simple as: Code: (Select All)
That's honestly all there is to it. |