I'm relatively new to DirectX and have to work on an existing C++ DX9 application. The app does tracking on a camera images and displays some DirectDraw (ie. 2d) content. The camera has an aspect ratio of 4:3 (always) and the screen is undefined.
我对DirectX比较陌生,不得不在现有的C ++ DX9应用程序上工作。该应用程序跟踪相机图像并显示一些DirectDraw(即2d)内容。相机的纵横比为4:3(始终),屏幕未定义。
I want to load a texture and use this texture as a mask, so tracking and displaying of the content only are done within the masked area of the texture. Therefore I'd like to load a texture that has exactly the same size as the camera images.
我想加载纹理并将此纹理用作蒙版,因此仅在纹理的蒙版区域内完成内容的跟踪和显示。因此,我想加载一个与相机图像尺寸完全相同的纹理。
I've done all steps to load the texture, but when I call GetDesc()
the fields Width
and Height
of the D3DSURFACE_DESC
struct are of the next bigger power-of-2 size. I do not care that the actual memory used for the texture is optimized for the graphics card but I did not find any way to get the dimensions of the original image file on the harddisk.
我已经完成了加载纹理的所有步骤,但是当我调用GetDesc()时,D3DSURFACE_DESC结构的字段宽度和高度是下一个更大的2次幂大小。我并不关心用于纹理的实际内存是否针对显卡进行了优化,但我没有找到任何方法来获取硬盘上原始图像文件的尺寸。
I do (and did, but with no success) search a possibility to load the image into the computers RAM only (graphicscard is not required) without adding a new dependency to the code. Otherwise I'd have to use OpenCV (which might anyway be a good idea when it comes to tracking), but at the moment I still try to avoid including OpenCV.
我这样做(并且做了,但没有成功)搜索可能只将图像加载到计算机RAM中(不需要图形卡)而不向代码添加新的依赖项。否则我将不得不使用OpenCV(在跟踪时可能是一个好主意),但目前我仍然试图避免包括OpenCV。
thanks for your hints, Norbert
谢谢你的提示,诺伯特
2 个解决方案
#1
D3DXCreateTextureFromFileEx with parameters 3 and 4 being
D3DXCreateTextureFromFileEx,参数为3和4
D3DX_DEFAULT_NONPOW2.
After that, you can use
之后,你可以使用
D3DSURFACE_DESC Desc;
m_Sprite->GetLevelDesc(0, &Desc);
to fetch the height & width.
获取高度和宽度。
#2
D3DXGetImageInfoFromFile may be what you are looking for.
D3DXGetImageInfoFromFile可能就是你要找的东西。
I'm assuming you are using D3DX because I don't think Direct3D automatically resizes any textures.
我假设您正在使用D3DX,因为我不认为Direct3D会自动调整任何纹理的大小。
#1
D3DXCreateTextureFromFileEx with parameters 3 and 4 being
D3DXCreateTextureFromFileEx,参数为3和4
D3DX_DEFAULT_NONPOW2.
After that, you can use
之后,你可以使用
D3DSURFACE_DESC Desc;
m_Sprite->GetLevelDesc(0, &Desc);
to fetch the height & width.
获取高度和宽度。
#2
D3DXGetImageInfoFromFile may be what you are looking for.
D3DXGetImageInfoFromFile可能就是你要找的东西。
I'm assuming you are using D3DX because I don't think Direct3D automatically resizes any textures.
我假设您正在使用D3DX,因为我不认为Direct3D会自动调整任何纹理的大小。