Getpixel

Previous topic - Next topic

WPShadow

Hi!

Eine Frage: Wie genau funzt das mit Getpixel? Ich möchte einen RGB - Farbwert fix auslesen, aber so ganz steige ich noch nicht dahinter! Vor allem bräuchte ich den Farbwert aufgeteilt in R/G/B!!!

glg

W.
AMD X2 4600, 2 GB Ram, ATI X1950 XTX, XP PRO SP2: GLB Premium 10.beta_dingsi, <(´.´<) Kirby Dance (>`.`)>
http://lostrevenant.blogspot.com
alea iacta est

Moru

Getpixel delivers a number that is built from three bytes put together. You need to split it in three parts.

If we see this as hexadecimal it gets easier to see how it's connected:
RR GG BB = RRGGBB

Each letter is half a byte, 4 bits. To get one part, just do this:
blue = bAND(color, 0x0000FF) // to get the blue component we remove all other information except the first eight bit (0xFF hex)
green = bAND(color, 0x00FF00)  // The green component is shifted eight bits (one byte)
green = green / 0xFF  // We divide with 256 (FF hexadecimal) to get it to move back to the lower area and give us a number between 0 and 255
red = bAND(color, 0xFF0000)
red = red / 0xFF
red = red / 0xFF  // We need to do it twice for red since it's even higher up. We could also divide with 0xFFFF

This will give you the separate color components if I wasn't thinking wrong somewhere now.

Kitty Hello

NO! it's BGR, not RGB (little endian).

See here:
http://www.glbasic.com/forum/index.php?topic=1529.0

Moru

Aw, I knew there was something stupid on intel

WPShadow

thx!!! That's really great!
AMD X2 4600, 2 GB Ram, ATI X1950 XTX, XP PRO SP2: GLB Premium 10.beta_dingsi, <(´.´<) Kirby Dance (>`.`)>
http://lostrevenant.blogspot.com
alea iacta est

Hemlos

Just making a note for you wpshadow,
since getpixel is so weak in the sense of accuracy.
An easy way to use it, is by detecting non-black colors.
Something like:
if getpixel()>rgb(0,0,0) then a color is detected.

i think the variation of getpixel has to do with the bit of the command, i think it is reading 256 colors.
but i could be wrong here, tho i have been using that command a lot, as you can see:
http://www.glbasic.com/forum/index.php?topic=2417.0
Bing ChatGpt is pretty smart :O

WPShadow

For the moment I'm working with "themes", but I want give the player a chance to make his own "theme".

Like the red one! I need the colors from this *.PNGs to write them into the DB. That's the idea!

[attachment deleted by admin]
AMD X2 4600, 2 GB Ram, ATI X1950 XTX, XP PRO SP2: GLB Premium 10.beta_dingsi, <(´.´<) Kirby Dance (>`.`)>
http://lostrevenant.blogspot.com
alea iacta est

Hemlos

#7
This is a piece from my 3d font object creator.
Use the image below with this image
Code (glbasic) Select

loadsprite "colorpicker420.png",0
TheColor:
IF init_color=FALSE; init_color=TRUE
LOCAL  mx,my,mb1,mb2
  CPColor=RGB(255,255,255)
   ENDIF

DRAWSPRITE 0,0,0 // draw pick color image

//grab a color
MOUSESTATE mx,my,mb1,mb2
IF mb1
CPColor=GETPIXEL(mx-1,my-1)
ENDIF

//show color selected box
DRAWRECT 500,100,100,100,RGB(255,255,255)
DRAWRECT 504,104,92,92,RGB(0,0,0)
DRAWRECT 504,104,92,92,CPColor


SHOWSCREEN
GOTO TheColor


[attachment deleted by admin]
Bing ChatGpt is pretty smart :O

Schranz0r

#8
So, erstens :

HIER ist das Deutsche Forum, hier wird Deutsch geschrieben!
(Hemlos soll sich lieber um die englische Abteilung kümmern)

zweitens:

Getpixel ist einfach zu langsam sowas zu machen, da wirst du keine Freude dran haben !

Schau lieber das du die Sachen die änderbar sein sollen mit verscheidenen Farben hinterlegen kannst.
Sprich:

Du benutzt ja eh PNG's also kannst du die Alphatransparentz ja nutzen und das was nicht veränderbar sein soll so zeichen und alles was ne andere Farbe bekommen soll einfach hinter das PNG setzen!
So schaut es immer duch das PNG durch, und ist um ein 100-Faches schneller als GetPixel
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Hemlos

#9

Die codesnip oben ist nicht langsam. : P
Bing ChatGpt is pretty smart :O

Schranz0r

ENGLISH:

Hemlos sorry, but that translationtool is realy bad!  :puke:
Please write him a PM or something. Some of us can not spreak english as well, so they dont understand what you are posting, if they have the same problem!
WPShadow can post your solution, if its work.

###################################################

DEUTSCH:

Entschuldigung  Hemlos, aber der Übersetzer ist echt schelcht!  :puke:
Bitte schreibe ihn eine PM oder sowas. Manche von uns können nicht so gut englisch, so das sie nicht verstehen was du schreibst, wenn sie das selbe Problem haben!
WPShadow kann die lösung dann posten, wenn es geht.
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Hemlos

#11
Si senior, mi casa est su casa. PM a solution code when i can just post it? We all speak glbasic here dont we?

http://www.glbasic.com/forum/index.php?topic=2448.0
Bing ChatGpt is pretty smart :O