Advertisement Jump to content
Sign in to follow this  

Reading ARGB values from textures in MDX/C#

This topic is 4316 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

Hey, I'm trying to get the contents of a certain texture level as an array of ARGB colors from a Texture in Managed DirectX 9 and C#. The code for loading the texture is
Texture texture = TextureLoader.FromFile(
                    0, 0, 0,
                    Filter.Linear, Filter.Linear,
Note that I use Format.Unknown (so the source format is taken which is DDS) and that I'm using the default pool because I *think* this has higher performance. I tried to lock a rectangle by
Color32[] colors = (Color32[])texture.LockRectangle(typeof(Color32), nLevel, LockFlags.ReadOnly, out pitch, width * height);
which throws an exception if I use the default pool (works with managed). If I change the pool to managed, I still have the problem that the function does not return ARGB colors but something weird. If I change Format to Format.A8R8G8B8, this works, but my texture is no longer compressed, which is very bad. Since I'm quite new to DX, I don't know what's the "usual" way to read back texture values. All I actually want to do is to compute the average color of a texture. Any easy way to do that? Any good books on this topics? Lutz

Share this post

Link to post
Share on other sites
Default resource can not be locked because use only video memory.
Compressed resource can not be read as usual because is not standard value but a special one to compress data. Probably there is an algorithm to read.
To get texture information use TextureLoader.ImageInformationFromFile to see what type of texture format you are using. When you pass A8R8G8B8 you are converting it, not using the image format.

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!