Read some pixels in an Image
Monkey Forums/Monkey Programming/Read some pixels in an Image
| ||
Hi, Is it possible to read a pixel but in an image ? Just because i would like to make a simple background collision system using two images for each part of a level : 1) The drawn image that show the background 2) A hidden image with 2+ colors to calculate collisions. Thanks for your help EDIT: Finally, i've discovered 'minib3d' and i'll try it. |
| ||
Are you sure that you need pixel perfect collision or will box-vs-box work? If you need pixel perfect collision I found this yesterday (as I was looking for the same thing as you): http://www.monkeycoder.co.nz/Community/posts.php?topic=3488 It can be modified quite a bit to probably suit you pretty good. |
| ||
You can't read it directly. You can render an image to the backbuffer and use ReadPixels() to get the data in an array, though. If you wanted to make collision masks, you could then convert these into bitmasks, with 32 pixels stored in each int. |
| ||
This should be possible... Why can i use WritePixels to write direct to image, and why can i not read pixels from image to array? using BackBuffer is bad! my solution is to use a raw bin data format ro read this to array... |
| ||
I needed something like this for a recent project (needed to know the color of a square on a map): I used 'Export to .h' in GIMP, which gives a c-style array which can be pasted into code as a monkey array (only works for fixed maps/levels, of course). I suppose you could automate that conversion if you had lots of maps/levels. Obv, have to be careful with the color map, the ordering can change etc. For a 2-4 colour collision map, its not a bad solution. |
| ||
Thanks a lot for your help. |
| ||
dragon, I'm guessing that nobody knows whether an image will be stored in normal memory or not. Or maybe it's just that different targets have different image storage formats. If you have a particular target in mind, you could try looking through the mojo code to see if you can find a better way. The backbuffer method works well enough IMO, it is easy to use. |