CDC :: DrawText问题 [英] Problem with CDC::DrawText

查看:226
本文介绍了CDC :: DrawText问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编码图像处理应用程序.我使用CDC:DrawText或CDC :: TextOut在显示的图像上绘制文本,如下所示:

I am coding an image processing application. I draw a text on the displayed image by using CDC:DrawText or CDC::TextOut like below:

/****Sample code: Start******/
//CDC* pDC = GetDC();
pDC->SetGraphicsMode(GM_ADVANCED);
pDC->SetMapMode(MM_ISOTROPIC) ;
pDC->SetViewportOrg(CPoint(100, 100));
pDC->SetWindowExt(CSize(100, 100));
pDC->SetViewportExt(CSize(100*zoomRatio, 100*zoomRatio));
XFORM xForm;
xForm.eM11 = 1;
xForm.eM12 = 0;
xForm.eM21 = 0;
xForm.eM22 = 1;
xForm.eDx = -100;
xForm.eDy = -100;
pDC->SetWorldTransform(&xForm);
CRect rtText(0, 0, 100, 100);
CString strText = _T("Test");
pDC->DrawText(strText, rtText, DT_LET | DT_TOP);
//pDC->TextOut(rtText.left, rtText.top, strText);
/****Sample code: End******/


正确的结果是strText是从rtText的左上方绘制的
如果zoomRatio = 1,则DrawText和Text out这两个函数会为我提供正确的结果.但是,当我缩放导致zoomRatio更改的图像时,只有TextOut函数会为我提供正确的结果,而DrawText函数会为我显示错误的结果将strText移动到rtText中的另一个位置.
我一直在尝试找到一种使用DrawText进行缩放的解决方案,但失败了.
任何人都知道此问题,请让我知道.
预先谢谢您.


The right result is that the strText is drawn from the left-top of the rtText
the two functions, DrawText and Text out, give me the right results if the zoomRatio = 1. However when I scale the image that cause zoomRatio changed, only the function TextOut gives me the right result and the function DrawText shows a wrong result that the strText is moved to another position in rtText.
I have been trying to find a solution to use DrawText for scaling but I failed.
Anyone know about this issue, please let me know.
Thank you in advance

推荐答案

请忽略我之前的查询.
我在一个简单的Win32程序(即不是MFC)中尝试了此操作,并且使用TextOut()DrawText()可以正确缩放文本.您的代码中肯定还有上面未显示的其他内容.

[edit]
您在DC中使用什么字体?
{/edit]
Please ignore my previous query.
I tried this in a simple Win32 program (i.e not MFC) and the text scales correctly using TextOut() and DrawText(). There must be something else in your code that is not shown above.

[edit]
What Font are you using in your DC?
{/edit]


我不太了解转换矩阵的数学原理,但查看您在XFORM结构中使用的值,我认为您是在转换到自己之外的位置视口.将eDxeDy的值更改为小于100的值(以加号或减号10开头),然后查看与您希望文本显示的位置如何匹配.
I do not really understand the mathematics of transform matrices, but looking at the values you are using in your XFORM structure, I think you are transforming to a location outside of your viewport. Change the values of eDx and eDy to something less than 100 (start with plus or minus 10) and see how that matches with where you want your text to appear.


这篇关于CDC :: DrawText问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆