Aaron de Windt
Aaron de Windt

Reputation: 17718

How can I get and set pixel data in XNA?

I have a texture2D where I want to get the color of a specified pixel. Do something with it and put a new color in an other texture2D.

I will need to do this with all the pixels in the texture. How can I do this.

No pixel shader's please. It need to be in C#

Upvotes: 3

Views: 5055

Answers (2)

Aaron de Windt
Aaron de Windt

Reputation: 17718

I found my problem.

When I was trying to get the color of a pixel the Alpha value of the color was 0. This means that the color would be completely transparent. To solve it I just needed to change the Alpha value to 255.

I think that this happened because I am using an jpg file. Jpg file's do not support Alpha values.

Upvotes: 0

David Brown
David Brown

Reputation: 36269

The Texture2D class contains the GetData and SetData methods that should do exactly what you want.

Upvotes: 2

Related Questions