This is my first post here and I’m fairly desperate.
My issue is that I’m supposed to make a game for a client (more of a friend favour type of thing so no pay 🙁 but meh jobs a job and I said I could do it, build rep and all that)
im using XNA 4 and therefore C#.
Now I need to figure out a way to count pixels of a certain colour, black to be specific. That’s it.
I have drawn a bunch of sprites and they are NOT of black. Some of them are UI but they are all at the side of the screen so I should be able to ignore those pixels right?
I figured I should be able to read the buffers once I have made all my draw calls. But I just can’t find any internet stuff (that’s readable) that tells me whether or not that’s even possible.
Read is the colour of the pixels I’m interested in is all I need to do. Lets say everything from width 50 to the edge of the window for example.
C# and XNA 4 answers are what i need.
whether you give me the answer on a silver platter or point me in the direction of something that will tell me how to do the various parts of it.
As a programmer goes I still count as a noob, just… a trained noob, so i might ask stupid questions to your excellent answers 🙂
You should be able to use GraphicsDevice.ResolveBackBuffer()
to copy the screen to a ResolveTexture2D. Then you can use Texture2D.GetData() to store the texture’s color data in a Color[] array.
From there you should be able to do your thing to count the colors while ignoring edge pixels.