|
|
|
date: Wed, 16 Jul 2008 16:14:24 +0200,
group: microsoft.public.win32.programmer.gdi
back
Rounding errors between GDI+ & GDI ...
Hello,
Please consider the following code :
void Test (HDC hDC)
{
// Set graphics mode to 72 dpi ...
SetMapMode(hDC, MM_ISOTROPIC);
SetWindowExtEx(hDC, 72, 72, NULL);
SetViewportExtEx(hDC, GetDeviceCaps(hDC, LOGPIXELSX),
GetDeviceCaps(hDC, LOGPIXELSY), NULL);
SetGraphicsMode(hDC, GM_ADVANCED);
// Draw a 2x2 inch rectangle using GDI
HBRUSH hbOld = (HBRUSH)SelectObject(hDC,
(HBRUSH)GetStockObject(NULL_BRUSH));
Rectangle(hDC, 100, 100, 100 + 144, 100 + 144);
SelectObject(hDC, hbOld);
// Draw over a 2x2 inch rectangle using GDI+
Graphics g(hDC);
SolidBrush br(Color(200, 255, 128, 0));
g.FillRectangle(&br, 100, 100, 144, 144);
}
It demonstrates that if you draw a GDI+ primitive over a GDI one, they
do not perfectly overlap when the GDI mapping mode is not trivial. I
guess that the Graphics objet performs some additionnal transformations
to mimic the GDI mapping mode. Problem is: the result is not the same as
drawing through the GDI internal matrix.
Any clue how to bypass this problem (without giving up the GDI
transformations of course)?
Thanks,
Jean-Ed.
date: Wed, 16 Jul 2008 16:14:24 +0200
author: Jean-Edouard Lachand-Robert
Re: Rounding errors between GDI+ & GDI ...
I have also discovered that DPtoLP returns different values depending on the mapping
modes, so there are several serious problems of which you seem to have identified another.
GDI+ uses GM_ADVANCED mode, and that's where the errors occur.
See my essay on errors in Windows documentation at
http://www.flounder.com/msdn_documentation_errors_and_omissions.htm#DPtoLP
joe
On Wed, 16 Jul 2008 16:14:24 +0200, Jean-Edouard Lachand-Robert
wrote:
>Hello,
>
>Please consider the following code :
>
>void Test (HDC hDC)
>{
> // Set graphics mode to 72 dpi ...
> SetMapMode(hDC, MM_ISOTROPIC);
> SetWindowExtEx(hDC, 72, 72, NULL);
> SetViewportExtEx(hDC, GetDeviceCaps(hDC, LOGPIXELSX),
>GetDeviceCaps(hDC, LOGPIXELSY), NULL);
> SetGraphicsMode(hDC, GM_ADVANCED);
>
> // Draw a 2x2 inch rectangle using GDI
> HBRUSH hbOld = (HBRUSH)SelectObject(hDC,
>(HBRUSH)GetStockObject(NULL_BRUSH));
> Rectangle(hDC, 100, 100, 100 + 144, 100 + 144);
> SelectObject(hDC, hbOld);
>
> // Draw over a 2x2 inch rectangle using GDI+
> Graphics g(hDC);
> SolidBrush br(Color(200, 255, 128, 0));
> g.FillRectangle(&br, 100, 100, 144, 144);
>}
>
>
>It demonstrates that if you draw a GDI+ primitive over a GDI one, they
>do not perfectly overlap when the GDI mapping mode is not trivial. I
>guess that the Graphics objet performs some additionnal transformations
>to mimic the GDI mapping mode. Problem is: the result is not the same as
>drawing through the GDI internal matrix.
>
>Any clue how to bypass this problem (without giving up the GDI
>transformations of course)?
>
>Thanks,
>Jean-Ed.
date: Thu, 31 Jul 2008 04:43:44 -0400
author: Joseph M. Newcomer
|
|