Hi ZeC
Sorry, not had time to really work on this one. I would suggest a change to the Texture2D class that stores the image data. When creating a texture the image data is loaded into a variable called data inside Texture2D. This stores the raw image data that is going to be used to by the OpenGL ES texture.
If you don't free that data structure as is currently done, you could create a class in Texture2D that accesses that data to retrieve the color of the pixel specified.
To access the correct location in the data and color information you would need to know the format of the image, which is worked our in Texture2D already. With this information you can then access the pixel data and read the color info as below.
- Code: Select all
uint *pixel = data_;
pixel = pixel + (y * _width) + x;
c.r = *pixel & 0xff;
c.g = (*pixel >> 8) & 0xff;
c.b = (*pixel >> 16) & 0xff;
c.a = (*pixel >> 24) & 0xff;
The example above is getting data for an image which is RGBA888. A forum thread on the Cocos2D iPhone site discusses this very issue using the same kind of solution as above
http://www.cocos2d-iphone.org/forum/topic/2449Hope that helps.
Mike