Get RGB values from ReadPixel

BlitzMax Forums/BlitzMax Beginners Area/Get RGB values from ReadPixel

Juxta(Posted 2009) [#1]
Hi guys,

Just wondering how I'd go about getting the individual Red, Green and Blue values from the ReadPixel() returned 32 bit value?

The idea I've been playing with is loading an image, locking it, getting the top left pixel value and then extracting the RGB values from that to set the mask colour. Releasing the image then loading it again with the right mask colour set.

Any ideas?


xlsior(Posted 2009) [#2]
http://www.blitzbasic.com/codearcs/codearcs.php?code=2236 (among others)

For common things like, it pays to take a peek at the code archives -- most likely you'll find what you're looking for there


Juxta(Posted 2009) [#3]
Thanks xlsior,

I tried doing forum searches, but I must have been using the wrong search terms.

:)


xlsior(Posted 2009) [#4]
I tried doing forum searches, but I must have been using the wrong search terms.


Most of this kind of stuff is in the code archives, which unfortunately aren't searchable through the built-in forum search feature.

You can either browse them directly here: http://www.blitzbasic.com/codearcs/codearcs.php

Or it can be beneficial to go to google.com, and type your search words there in combination with a "site:blitzbasic.com" and possible .bmx (for Blitzmax) or .bb (for the rest)
which will include the code archives...


TomToad(Posted 2009) [#5]
The idea I've been playing with is loading an image, locking it, getting the top left pixel value and then extracting the RGB values from that to set the mask colour. Releasing the image then loading it again with the right mask colour set.


It might be better if you load it into a pixmap, extract the information, then load the image from the pixmap.

Local Pixmap:TPixmap = LoadPixmap("Image.png") 'Load image into a pixmap

ExtractMyMaskInfo() 'Whatever function you use to extract the rgb from the pixel
SetMaskColor Red,Green,Blue 'Set the mask color
Local Image:TImage = LoadImage(Pixmap) 'load the pixmap into an image
Pixmap = Null 'free the pixmap if you want to



Perturbatio(Posted 2009) [#6]
for searching the code archives btw, you could do: http://www.google.co.uk/search?hl=en&ei=ZpqiScCHN9LjtgexgZH3DA&sa=X&oi=spell&resnum=1&ct=result&cd=1&q=site%3Ahttp%3A//www.blitzbasic.com/codearcs+Color+to+RGB&spell=1


Juxta(Posted 2009) [#7]
@TomToad - that's a cleaner way of doing it. Thanks. I was just playing around with different graphics I'd found online and, while most use magenta, they don't all have the same mask colour.

From what I've read the garbage collection in BlizMax is pretty good as long as I'm diligent about freeing the pointer.

@Perturbatio - thanks for that. I just realised to that you can sort the code archives by .bb or .bmax file.

Hmmm looking at all this my next project is to complete and entire game using only snippets from the code archives ;)