Getting RGB values from an image

BlitzMax Forums/BlitzMax Beginners Area/Getting RGB values from an image

sandav(Posted 2007) [#1]
Is there any way to find the RGB value of a pixel in an image that has been drawn after setColor has been used to change the drawing color to something other than 255,255,255? I'm attempting to make a Gui module that uses both greyscale images, and generated rectangles, lines and points, in such a way that I can set the color to like OliveGreen (131,193,124) for instance, and have the lines and rectangles generated be the same color as the greyscale graphics. I suspect my solution may lie in dealing with pixMaps some how, but I have no idea how to go about it.

Here's what I have so far, but its not working properly

Function DrawBox(UpperLeftX%,UpperLeftY%,width%,Height%,R%,G%,B%

SetAlpha(.7)
SetColor(r,g,b)
DrawRect(UpperLeftX,UpperLeftY,Width,Height) 'draws a semi-transparent rectangle for the body of the box
SetAlpha(1)
DrawImage(GuiImage,UpperLeftX-16,UpperLeftY-16,13)  'fancy looking corners from images
DrawImage(GuiImage,UpperLeftX+width,UpperLeftY-16,14)
DrawImage(GuiImage,UpperLeftX-16,UpperLeftY+height,15)
DrawImage(GuiImage,UpperLeftX+width,UpperLeftY+height,16)
SetColor(51 + r Mod 255, 51 + g Mod 255,51 + b Mod 255) 'side lines
DrawRect(UpperLeftX,UpperLeftY-3,width,3)      
DrawRect(UpperLeftX,UpperLeftY+height,width,3)
DrawRect(UpperLeftX-3,UpperLeftY,3,Height)
DrawRect(UpperLeftX+width,UpperLeftY,3,Height)
SetColor(108 + r Mod 255,108 +g Mod 255 ,108 +b Mod 255)  'middle stripes
DrawLine(UpperLeftX,UpperLeftY-2,UpperLeftX+width-1,UpperLeftY-2)
DrawLine(UpperLeftX,UpperLeftY+height+1,UpperLeftX+width-1,UpperLeftY+height+1)
DrawLine(UpperLeftX-2,UpperLeftY,UpperLeftX-2,UpperLeftY+Height-1)
DrawLine(UpperLeftX+width+1,UpperLeftY,UpperLeftX+width+1,UpperLeftY+height-1)
SetColor(255,255,255)
endfunction


the colors I'm trying to match are (51,51,51), and (108,108,108) I tried to do it by SetColor(51 + r Mod 255,51 +g Mod 255 ,51 +b Mod 255), and SetColor(108 + r Mod 255,108 +g Mod 255 ,108 +b Mod 255)
but that hasn't been working for me. Any help would be greatly appreciated.


H&K(Posted 2007) [#2]
Yep, you have to make it a pixmap, and then use readpixel


sandav(Posted 2007) [#3]
how would that work even after the color has been changed from the one in the file by using the SetColor function?


tonyg(Posted 2007) [#4]
Setcolor doesn't change the pixmap.


CS_TBL(Posted 2007) [#5]
Making a pixmap out of an image only changes a few bytes for an address I assume? It's not like the whole pic is copied (as a complete instance) to a pixmap instance? E.g. Can one do fast animations by constant editing of pixmaps of those images?


sandav(Posted 2007) [#6]
I did some testing, and I don't think that readpixel is the solution to my problem. I want to be able change the colors displayed when drawing a png with the setColor function (or if I can get a similar effect with pixmaps, and then find the rgb value of the result, ie the rgb values being shown on the screen after a greyscale has been drawn using drawImage after setting setColor to something other than 255,255,255. Perhaps I'm going about this the wrong way though, would it be better if instead I drew my lines and rectangles with a known rgb, and then used write pixel to change values in a pixmap?