Is there a cross platform, all target GetPixel?

Monkey Forums/Monkey Programming/Is there a cross platform, all target GetPixel?

EdzUp(Posted 2013) [#1]
Im looking for a completely cross target solution to GetPixel im just wondering if its possible to just drop in a import blah and call GetPixel like we used to in BlitzMax.

Anyone have any code that does this without using diddy?


MikeHart(Posted 2013) [#2]
Isn't it called ReadPixel?


samowitsch(Posted 2013) [#3]
I made this little method/function for me that checks for one pixel and returns the rgb values.

The GetPixel method was removed in the Diddy Framework.

	Method CustomGetPixel:Int[](x:Int, y:Int)
		Local Pixels:Int[1] 'store 1 pixel
		ReadPixels(Pixels, x, y, 1, 1)
		
		Local a : Int = ( Pixels[0] Shr 24 ) & $ff
		Local r : Int = ( Pixels[0] Shr 16 ) & $ff
		Local g : Int = ( Pixels[0] Shr 8 ) & $ff
		Local b : Int = Pixels[0] & $ff
		
		Local PixelValues:Int[] = [r,g,b]
				
		Return PixelValues
	End Method



EdzUp(Posted 2013) [#4]
Ah thanks for that didn't know there was readpixel. Thanks guys :)


Raul(Posted 2013) [#5]
But, you should know that this method will actually read the pixel which is rendered on the screen in that moment.

This means that, IN REAL TIME, if you have a PNG with transparent bg and you are drawing it over a nice colorfull background and you call ReadPixel to see what color you have... you will receive that background color.


therevills(Posted 2013) [#6]
you will receive that background color

But you can mask that colour by bit-shifting (as long as it is a single colour which you dont care about).


Raul(Posted 2013) [#7]
yes. you can do that when loading the level for example..


EdzUp(Posted 2013) [#8]
Well its gonna help a lot, i don't see why a simple getpixel wasn't added to monkey for compatibility, also a loadpixmap etc


AdamRedwoods(Posted 2013) [#9]
, i don't see why a simple getpixel wasn't added to monkey for compatibility, also a loadpixmap etc

i can answer why no LoadPixmap (which miniB3D implements BTW):
because mobile devices limit the amount of memory each app can use, so in order to maximize memory constraints, ESPECIALLY in android, Mojo2D dumps the loaded image after it's bound to the graphics card.

Android's Java heap is NOT effected by bound textures, so this can save a bit of room, but at the expense of having to reload images when the context is lost.


EdzUp(Posted 2013) [#10]
Ah ok :)