Jump to content
  • Advertisement
Sign in to follow this  
Dawid Zwiewka

How to get texture width and size?

This topic is 2150 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 need to know what are width and height of texture BUT not power of two after DX loading but real size in file. F.e. image 1024x768 i need to know that is 1024x768 not 1024x1024 like DX says.

Share this post

Link to post
Share on other sites

Is this DX9?


Most textures are a power of two for hardware optimizations. You don't need to use the whole area, for example a texture atlas has many different images packed into the same texture.


The IDirect3DTexture9 interface has a method called GetLevelDesc, it Retrieves a level description of a texture resource.

typedef struct D3DSURFACE_DESC {
  D3DFORMAT           Format;
  DWORD               Usage;
  D3DPOOL             Pool;
  DWORD               MultiSampleQuality;
  UINT                Width;
  UINT                Height;

Share this post

Link to post
Share on other sites

you have a very good tutorial to load textures on DX11 http://www.rastertek.com/dx11tut05.html


basically you need to call this function

HRESULT D3DX11CreateShaderResourceViewFromFile(
_In_   ID3D11Device *pDevice,
_In_   LPCTSTR pSrcFile,
_In_   D3DX11_IMAGE_LOAD_INFO *pLoadInfo,
_In_   ID3DX11ThreadPump *pPump,
_Out_  ID3D11ShaderResourceView **ppShaderResourceView,
_Out_  HRESULT *pHResult


result = D3DX11CreateShaderResourceViewFromFile(device, filename, NULL, NULL, &m_texture, NULL);

and to get the size you would need to cast the ID3D11ShaderResourceView  to ID3D11Texture2D and get its Desc


ID3D11Resource resource;
ID3D11Texture2D texture2D;






if you only want to know the size of the texture without loading you can use this 

HRESULT D3DX11GetImageInfoFromFile(
_In_   LPCTSTR pSrcFile,
_In_   ID3DX11ThreadPump *pPump,
_In_   D3DX11_IMAGE_INFO *pSrcInfo,
_Out_  HRESULT *pHResult

D3DX11_IMAGE_INFO *m_info;
D3DX11GetImageInfoFromFile( "path/to/img.jpg", NULL, &m_info, NULL ); 

this will fill m_info with the struct information below

typedef struct D3DX11_IMAGE_INFO {
UINT                     Width;
UINT                     Height;
UINT                     Depth;
UINT                     ArraySize;
UINT                     MipLevels;
UINT                     MiscFlags;
DXGI_FORMAT              Format;
D3D11_RESOURCE_DIMENSION ResourceDimension;







Share this post

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

  • Advertisement

Important Information

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

GameDev.net 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!