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.
.



Relevant Pages

  • Re: Writing a Game, huge image scroll problem
    ... The big problem here is GDI+ is not accelerated by the graphics card. ... a) Draw the bg image on clone graphics a_1) I create an array with all the scenario huge images a_2) I scan the array for check bounds/coords of each pic a_3) if there are two bg to draw i draw both i think that drawimage out of bound cannot affect internally the GDI+ engine, all is checked by itself so i don't need to check the bounds for clip the images a_4) NOTE that i pre-scan the array passing everytime only ONE or MAX TWO images to draw, not more... ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: DrawReversiblePoint?
    ... The ControlPaint methods are very limited and are there to sidestep the ... that all graphics systems have had for two decades or more. ... You could try to draw a bezier onto a graphics path, ... Answer those GDI+ questions with the GDI+ FAQ ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Anti-aliased drawing
    ... GDI+ is not reliant on .NET. ... You set the graphics SmoothingMode to ... SmoothingMode.AntiAlias then just draw your lines/shapes. ... boss has decided it's got to be a series of round dials. ...
    (microsoft.public.vb.general.discussion)
  • Re: Rounding errors between GDI+ & GDI ...
    ... GDI+ uses GM_ADVANCED mode, and that's where the errors occur. ... // Set graphics mode to 72 dpi ... ... // Draw over a 2x2 inch rectangle using GDI+ ... do not perfectly overlap when the GDI mapping mode is not trivial. ...
    (microsoft.public.win32.programmer.gdi)
  • RE: Anybody know any sample graphics applications built in c#?
    ... Actually GDI+ is the native graphics functions from windows, ... fast but it has a main problem, it uses a single buffer to draw. ... That you write on a buffer that is constantly copied to the video ... DirectX and not GDI. ...
    (microsoft.public.dotnet.languages.csharp)

Loading