Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am coding an image processing application. I draw a text on the displayed image by using CDC:DrawText or CDC::TextOut like below:
C++
/****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******/

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
Posted
Updated 22-Sep-11 22:47pm
v3

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]
 
Share this answer
 
v2
Comments
vuhuythao 23-Sep-11 4:51am    
Dear Richard,
Thank you for your reply.
I updated the new source code. I do not change any thing related fonts. You can check again. I hope that you can give me a solution.
Thank you very much
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900