ID3DXSprite显示一副图像时会对图像放大,如何修改不放大也不缩小原图

everything_at_once 2018-10-09 09:54:03
目前有一副png图像,分辨率为1440*900,显示的窗口也是1440*900
显示的时候,图像会被放大,造成显示不全
如何设置可以让1440*900的图像完整显示在1440*900的窗口上,既不放大,也不缩小。
...全文
311 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
draculamx 2018-10-15
  • 打赏
  • 举报
回复
directx9的话,CreateTexture的时候,一般要求,图片的长,宽,为2的次幂,比如你搞个长度为135的图片的话,由于有的显卡不支持非2次幂的纹理,所以就有可能出现模糊。。。

长:512 宽:128,这种就是符合要求的,他们都是2的次幂
WJN92 2018-10-14
  • 打赏
  • 举报
回复
太旧了,现在dx是可以调试的
everything_at_once 2018-10-12
  • 打赏
  • 举报
回复
引用 6 楼 draculamx 的回复:
ID3DXSprite,你用的是D3D9吗?我原来没有出现过这种情况啊,把你Render的代码放出来看看啊,不看代码怎么查问题
    

            D3DXCreateTextureFromFile(m_dev, _T("logo.png"), &m_pLogoTexture);
			m_dev->SetTexture(0, m_pLogoTexture);
			D3DXCreateSprite(m_dev, &m_pLogoSprite);     
   
            RECT rct;
			::GetWindowRect(m_wnd,&rct);
			//SetRect( &rct, 0, 0, 100, 100 );

			m_dev->BeginScene();
			{
				m_pLogoSprite->Begin(D3DXSPRITE_ALPHABLEND);
				m_pLogoSprite->Draw(m_pLogoTexture, NULL, NULL, NULL, 0xffffffff);
				m_pLogoSprite->End();
			}
			m_dev->EndScene();
draculamx 2018-10-11
  • 打赏
  • 举报
回复
ID3DXSprite,你用的是D3D9吗?我原来没有出现过这种情况啊,把你Render的代码放出来看看啊,不看代码怎么查问题
赵4老师 2018-10-09
  • 打赏
  • 举报
回复
关于Windows高DPI的一些简单总结
http://www.cnblogs.com/weiym/p/3555068.html

?
everything_at_once 2018-10-09
  • 打赏
  • 举报
回复
引用 1 楼 zhao4zhong1 的回复:
AdjustWindowRect The AdjustWindowRect function calculates the required size of the window rectangle, based on the desired client-rectangle size. The window rectangle can then be passed to the CreateWindow function to create a window whose client area is the desired size. BOOL AdjustWindowRect( LPRECT lpRect, // pointer to client-rectangle structure DWORD dwStyle, // window styles BOOL bMenu // menu-present flag ); Parameters lpRect Pointer to aRECT structure that contains the coordinates of the top-left and bottom-right corners of the desired client area. When the function returns, the structure contains the coordinates of the top-left and bottom-right corners of the window to accommodate the desired client area. dwStyle Specifies the window styles of the window whose required size is to be calculated. bMenu Specifies whether the window has a menu. Return Values If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, callGetLastError. Remarks A client rectangle is the smallest rectangle that completely encloses a client area. A window rectangle is the smallest rectangle that completely encloses the window, which includes the client area and the nonclient area. The AdjustWindowRect function does not add extra space when a menu bar wraps to two or more rows. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Requires Windows 95 or later. Windows CE: Unsupported. Header: Declared in winuser.h. Import Library: Use user32.lib. See Also Windows Overview, Window Functions, AdjustWindowRectEx, CreateWindow,RECT
经测试,输入1440*900,通过AdjustWindowRect返回矩形大小为4 23 1444 904,还是有放大情况,查过相关资料,应该和ID3DXSprite或加载Texture设置有关,这个正在试,目前这个放大不是一点,是很明显的放大,一副1440*900的图像显示在1440*900的显示器上后,缺失的右+下部分大约有五分之一
赵4老师 2018-10-09
  • 打赏
  • 举报
回复
AdjustWindowRect
The AdjustWindowRect function calculates the required size of the window rectangle, based on the desired client-rectangle size. The window rectangle can then be passed to the CreateWindow function to create a window whose client area is the desired size.

BOOL AdjustWindowRect(
LPRECT lpRect, // pointer to client-rectangle structure
DWORD dwStyle, // window styles
BOOL bMenu // menu-present flag
);

Parameters
lpRect
Pointer to aRECT structure that contains the coordinates of the top-left and bottom-right corners of the desired client area. When the function returns, the structure contains the coordinates of the top-left and bottom-right corners of the window to accommodate the desired client area.
dwStyle
Specifies the window styles of the window whose required size is to be calculated.
bMenu
Specifies whether the window has a menu.
Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, callGetLastError.

Remarks
A client rectangle is the smallest rectangle that completely encloses a client area. A window rectangle is the smallest rectangle that completely encloses the window, which includes the client area and the nonclient area.

The AdjustWindowRect function does not add extra space when a menu bar wraps to two or more rows.

QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Unsupported.
Header: Declared in winuser.h.
Import Library: Use user32.lib.

See Also
Windows Overview, Window Functions, AdjustWindowRectEx, CreateWindow,RECT


赵4老师 2018-10-09
  • 打赏
  • 举报
回复
像素纵横比 ?
everything_at_once 2018-10-09
  • 打赏
  • 举报
回复
引用 3 楼 zhao4zhong1 的回复:
关于Windows高DPI的一些简单总结 http://www.cnblogs.com/weiym/p/3555068.html ?
查看了当前电脑的设置,是100%,感觉和这个无关,我这边论坛上传不了图片,我做了一副100*100的图像,显示在100*100的矩形里,实际差了很多。后来用下面的方式暂时解决了。

D3DXMATRIX mat;

// 1440*900 渲染
D3DXMatrixTransformation2D(&mat, NULL, 0.0f, &D3DXVECTOR2(0.703f, 0.877f), NULL, 0, &D3DXVECTOR2(0.0f, 0.0f));

// 2*1920*1080
D3DXMatrixTransformation2D(&mat, NULL, 0.0f, &D3DXVECTOR2(1.0f, 0.52f), NULL, 0, &D3DXVECTOR2(0.0f, 0.0f));
经测试,1440*900的图片在1440*900分辨率的显示器上渲染需要设置 D3DXVECTOR2(0.703f, 0.877f), 3840*1080的图片在3840*1080的两个显示器上渲染需要设置 D3DXVECTOR2(1.0f, 0.52f), 这样图像才能显示完整,只是渲染出来的效果略微发虚,但还可以接受,具体什么原因还不清楚,后面再验证。
DXUT框架剖析 DXUT框架剖析(14) 摘要: 控件是用户接口的重要组成部分,为了便于用户操作,为程序界面添加各种控件是非常好的方法。DXUT框架为在Direct3D程序中添加各种控件提供了支持。为了便于加载控件和处理各控件的消息,通常先在窗口中加载对话框,然后在对话框中添加响应的控件,由对话框来管理控件。为了统一管理各个对话框,还需要定义对话框资源管理器类CDXUTDialogResourceManager的一个对象,在程序开始时,调用各个对话框的Init函数和对话框资源管理对象进行初始化 DXUT框架剖析(13) 摘要: DXUT框架对文本绘制进行了封装,提供了类CDXUTHelper来简化文本显示,使用该接口大体分为3个步骤:初始化ID3DXSpriteID3DXFont对象,显示文本,释放ID3DXSpriteID3DXFont对象。 DXUT框架剖析(12) 摘要: DXUT暂停函数: DXUTPause:将框架的内部计数器和(或)渲染过程设为暂停状态。 DXUTRenderingPaused:检查当前设备的渲染状态是否处在暂停状态。 DXUTIsTimePaused:检查当前设备的计时器是否处在暂停状态。 DXUT框架剖析(11) 摘要: DXUT统计函数: DXUTGetFPS: 获取当前每秒提交的帧数。 DXUTGetFrameStats:获取一个指向字符串的指针,该字符串包括每秒帧数、分辨率、后台缓冲区格式、深度缓冲区格式。 DXUTGetDeviceStats:获取一个指向字符串的指针,该字符串包括当前设备类型、顶点运算行为和设备名。 DXUT框架剖析(10) 摘要: 管理DXUT框架的函数: DXUTResetFrameworkState: 将框架状态重置为初始默认状态,之前设置的框架状态改变将失效。 DXUTShutdown: 触发程序终止和清空框架。 DXUTGetExitCode: 获取框架的退出代码。 DXUT框架剖析(9) 摘要: 下面列出允许改变DXUT行为和获取内部变量的函数,这些函数在使用DXUT框架的Direct3D程序中是非常实用的。 DXUT框架剖析(8) 摘要: Direct3D API的设计使程序能比较容易地处理各种错误,尽管大多数Direct3D API函数返回HTRSULT值,但只有一部分函数返回设备错误,如D3DERR_DEVICELOST或 D3DERR_DRIVERINTERNALERROR。但是通常的Direct3D应用程序使用多种API函数,当传递的参数不合要求时,将返回 D3DERR_INVALIDCALL。 当开发Direct3D应用程序时,应该检查所有的API调用是否成功,如果出现一个没有预测到的失败调用,应用程序应立即给出通知或记录该错误。使用这种方法,开发人员能很快发现哪些API函数的调用是不正确的。一个正确调用Direct3D API函数的应用程序应能安全地忽略大多数Direct3D API函数的失败调用,除了一些关键性的API函数,如Present()或TestCooperativeLevel(),这些函数返回的错误应用程序不能忽略。 DXUT框架剖析(7) 摘要: 框架也提供了帧事件,它在渲染过程中的每一帧被调用,应用程序应该注册并实现这些回调函数。 DXUT框架剖析(6) 摘要: 在窗口和设备创建好之后,应用程序需要使用消息循环处理窗口消息、更新和渲染场景、处理设备事件。应用程序可以实现自己的消息循环,也可以使用DXUT消息循环,注册相应的回调函数,可以让DXUT处理设备、帧消息事件。 为使用DXUT框架的消息循环,可以调用DXUTMainLoop()函数. DXUT框架剖析(5) 摘要: 应用程序可以通过DXUTSetCallbackDeviceChanging()设置回调函数来修改Direct3D设备的创建设置。 回调函数ModifyDeviceSettings()返回一个布尔值,如果应用程序返回 TRUE,DXUT框架继续像在正常情况下那样进行设备创建。如果返回FALSE,框架不能改变设备,如果已有一个设备,则继续使用当前设备。如果框架提出的请求是改变到一个应用程序不能使用的设备,应用程序可以拒绝该请求。例如,在一个多显示器配置中,默认情况下在显示器之间拖动窗口将使框架改变设备。但如果应用程序不能使用其他设备,它就必须拒绝这种改变并继续使用当前设备。 DXUT框架剖析(4) 摘要: 通常可以用标准的Direct3D方法Creat

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧