LEADTOOLS Support
Imaging
Imaging SDK Questions
mouse-draw rect map to img's rgn unprecise problem.
This topic and its replies were posted before the current version of LEADTOOLS was released and may no longer be applicable.
#1
Posted
:
Thursday, April 5, 2012 5:56:09 PM(UTC)
Groups: Registered
Posts: 11
I draw a rect by mouse,map this rect to piscure's rgn.and then draw the rgn.but they show not completely at the same pos. in attachement sample, the dotrect is the rng,the black sold is the original.and i find that, the bigger of image ,the bigger measurement error .
my code is this:
RECT rcScaled;
rcScaled.left=(int)((m_rcCLoneRect.left-m_rcDst.left)/(GetZoomPercent()/100.0)+0.5);
rcScaled.top=(int)((m_rcCLoneRect.top-m_rcDst.top)/(GetZoomPercent()/100.0)+0.5);
rcScaled.right=rcScaled.left+(int)((m_rcCLoneRect.Width()*100/GetZoomPercent()));
rcScaled.bottom=rcScaled.top+(int)((m_rcCLoneRect.Height()*100/GetZoomPercent()));
SetAutoRgnToFloater(TRUE);
LBitmapRgn Region(this);
Region.SetRgnRect(&rcScaled);
this->Repaint();
#2
Posted
:
Sunday, April 8, 2012 1:44:28 AM(UTC)
Groups: Registered, Tech Support
Posts: 179
The most likely cause of the difference is rounding errors. The GetZoomPercent() function returns integer, and all the calculations in your code are integer based.
This means you will not get accurate results this way.
A better way to convert from client coordinates to bitmap coordinates, is to use the formula in this forum post:
http://support.leadtools.com/cs/forums/34411/ShowPost.aspx
You can also use the same rectangles to do the inverse calculation from bitmap to client coordinates if you need it.
Mohamed Abedallah
Developer Support Engineer
LEAD Technologies, Inc.

LEADTOOLS Support
Imaging
Imaging SDK Questions
mouse-draw rect map to img's rgn unprecise problem.
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.