Jump to content
  • Advertisement
Sign in to follow this  
econobeing

[XNA 3.0] How to get pixel colors/data? [solved]

This topic is 3452 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to get the individual colors from a pixel in a Texture2D object. I put the data into a uint array:
this.colors = Content.Load<Texture2D>("colorbars");
this.bits = new uint[this.colors.Width * this.colors.Height];
this.colors.GetData<uint>(this.bits);

Then I try to grab an individual color value of a pixel in the array by the mouse position:
public uint getBlue()
{
	uint r = 0;
	if (this.getMousePosition().X >= 0 && this.getMousePosition().X <= this.colors.Width)
	{
		if (this.getMousePosition().Y >= 0 && this.getMousePosition().Y <= this.colors.Height)
                {
			r = this.bits[(int)this.getMousePosition().X * (int)this.getMousePosition().Y] & 0x00FF0000 >> 16;
                }
	}
	return r;
}

(The image is drawn at 0,0 so it should be fine for now) When I do that, all I get are values like 0,1,195,196,and 204. It doesn't even matter what color my cursor is over. I tried to do this a few months ago, and just picked it up again, so I'm re-using code from then. So I'm really not even fully sure what the "r = this.bits[];" line is doing, I don't even know if I fully understood it back when it was first attempted. Am I on the right track, or did I completely miss the target on how to do this? EDIT: got it: http://msdn.microsoft.com/en-us/library/bb197084.aspx [Edited by - econobeing on January 6, 2009 12:52:05 PM]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!