D3DXCreateTextureFromFileEx接口获取图片的实际数据

之前想要使用D3DXCreateTextureFromFileEx获取到129*129图片的图片信息,

接口的参数如下设置:

D3DXCreateTextureFromFileEx(mD3dDevice, lpFileName, D3DX_DEFAULT, D3DX_DEFAULT, 

                                                           D3DX_DEFAULT, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT,

                                                           D3DX_DEFAULT, 0, 0, NULL, &height);

结果获取到的总是2^n的大小,应该是Mipmap的那一阶级的图片大小,而我想要是图片的真实大小。

今天查了下Direct SDK, D3DXCreateTextureFromFileEx接口中的D3DXIMAGE_INFO参数,

D3DXIMAGE_INFO *pSrcInfo;

pScrInfo [in, out] Pointer to a D3DXIMAGE_INFO structure to be filled with a description of the data in the source image file, or NULL.

这样就可以获取到图片的真实信息,而不是Mipmap的大小。


之外,最好将D3DXCreateTextureFromFileEx中的MipLevels的值设置为D3DX_FROM_FILE,这样加载图片时,不会创建Mipmap。这样可以省去创建Mipmap chain的空间。

Direct SDK中显示:

MipLevels [in] Number of mip levels requested, If this value is zero or D3DX_DEFAULT, a complete mipmap chain is created. If D3DX_FROM_FILE, the size will be taken

exactly as it is in the file, and the call will fail if this violates device capabilities.

你可能感兴趣的:(D3DXCreateTextureFromFileEx接口获取图片的实际数据)