C# - Retrieving the images size

EFileTahi-A

Contributor
Joined
Aug 8, 2004
Messages
623
Location
Portugal / Barreiro
As you all know, when using a texture in Direct3D we must inform the texture's size when using it as a sprite in a form of a rectangle.

What I need to know is how can I retrieve the picture's size which is being assigned to the texture object so that I can create the apropriate rectangle to display the correct texture aspect ratio. Like, if I load a 32x32 picture into a texture object I also need to inform the Sprite.Draw command that the texture is a 32x32 image.

Pseucode:

Code:
//Check the apropriate texture size to use
if the original image's size which was loaded into the current texture is 32x32
     sprite.draw(texture with size 32x32)
else if image size is 128x128
     sprite.draw(texture with size 128x128)
(...)

tks for any possible help on this one
 
When I load textures, I use the TextureLoader.FromFile method. The last argument I pass is a reference to an ImageInfo class. The ImageInfo gets filled, and you can look at its .Width and .Height values.

Also, if you already have the texture loaded, you can do the following:

SurfaceDescription sd = texture.GetLevelDescription(0);

And look at ds.Width and ds.Height.

--Vic--
www.flatredball.com
 
Back
Top