Get Pixel Color from an image texture

iPhone Discussions

Re: Get Pixel Color from an image texture

Postby A Person » Sun Oct 24, 2010 7:28 pm

Oh sorry i didn't know that you didn't have your images on the screen, in that case you most definitely have to get your data from Texture2D. There is one other way though, maybe if you drew your tiles somewhere off the actually screen at (-160, -240) or something then it would still be possible to read the pixels using my function. If you do try that i'd like to know how it works as this pixel reading stuff could actually be useful to me but for now i'll keep trying with Texture2D.
there's no place like ~/
A Person
 
Posts: 161
Joined: Fri Sep 25, 2009 3:45 am
Location: Canada

Re: Get Pixel Color from an image texture

Postby ZeCreator » Mon Oct 25, 2010 9:31 pm

If you are around Mike, there is some questions about the Image Texture Datas :p

Thanks in advance -)
ZeC
ZeCreator
 
Posts: 13
Joined: Sat Oct 23, 2010 1:53 pm

Re: Get Pixel Color from an image texture

Postby mike » Mon Oct 25, 2010 11:20 pm

I've just been catching up on this thread. I need to have a think about this one...

Mike
mike
 
Posts: 670
Joined: Fri Aug 21, 2009 2:10 pm

Re: Get Pixel Color from an image texture

Postby ZeCreator » Tue Nov 09, 2010 6:21 pm

Hi,

we have make some try, but no more -(
I think only you have the keys Mike.
ZeCreator
 
Posts: 13
Joined: Sat Oct 23, 2010 1:53 pm

Re: Get Pixel Color from an image texture

Postby ZeCreator » Fri Nov 26, 2010 10:05 am

Hi guys, hi Mike.

Any help ? or a way to resolve it ?
ZeC.
ZeCreator
 
Posts: 13
Joined: Sat Oct 23, 2010 1:53 pm

Re: Get Pixel Color from an image texture

Postby mike » Sat Nov 27, 2010 1:48 pm

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/2449

Hope that helps.

Mike
mike
 
Posts: 670
Joined: Fri Aug 21, 2009 2:10 pm

Previous

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron