# DX GUI - Getting an image resolution

## Recommended Posts

Sagito    129
Hi... I'm trying to create a GUI/menu system in my DirectX 9.0c application, and I would like to load image files to the interface. That is relatively easy to do using sprites, but I wanted the image file object to throw mouse-over events and to do so, I need to know it's upper-left corner and the image dimensions. Is there any way in DirectX or in Windows API that retrieve these informations about an image, or will I have to create a parser for each and every image file type I want to read? Thanks in advance...

##### Share on other sites
dave    2187
You can get the resolution of the back buffer from the IDirect3DDevice*, get the back buffer surface and then the surface details. You can get the size of a texture the same way.

As a word of advice, don't specify the position of controls in pixels, do it in percent accross the screen, then convert the mouse position. This is for the internal representation of pixels BTW, in script files you can specify how you want, so long as you convert. You can deal with differentresolutions more easily this way.

##### Share on other sites
Sagito    129

Thanks for the quick reply... =)

It worked perfectly. This is what I've done, based on what you said:

 IDirect3DTexture9* test;D3DXCreateTextureFromFile(device, L"test.bmp", &test);D3DSURFACE_DESC descriptor;test->GetLevelDesc(0, &descriptor);cout << descriptor.Width << ", " << descriptor.Width << endl;

With which image file types does this work with, btw?

Once again, thanks for your answer, it really helped a lot... (^^,)

##### Share on other sites
sirob    1181
Quote:
 DX SDK Article about D3DXCreateTextureFromFileThis function supports the following file formats: .bmp, .dds, .dib, .hdr, .jpg, .pfm, .png, .ppm, and .tga. See D3DXIMAGE_FILEFORMAT.

The SDK Docmentation is your friend. Use it.