## mixing gdi and gdi+

### mixing gdi and gdi+

Hi, I am writing a component.

I do something like the Paint method below.

The problem is that the two Canvas.Ellipse calls dosn't draw on the same
place on the canvas, so GDI plus must change the coordinate system somehow.
How can I fix this?

regards,
David

procedure TMyControl.Paint;
var
g: TGPGraphics;
p: TGPPen;
begin
g := TGPGraphics.Create(Canvas.Handle);
p := TGPPen.Create(MakeColor(127, 255, 0, 255));
try
Canvas.Ellipse(Bounds(10, 10, 20, 20));

g.DrawEllipse(10, 10, 20, 20);

Canvas.Ellipse(Bounds(10, 10, 20, 20));
finally
g.Free;
end;
end;

--
mvh,
David

### mixing gdi and gdi+

Hmm... There seems to be something fundamentally different between the way
the two libraries calculates...

Example:
Canvas.Rectangle(Bounds(10, 10, 1, 1));  // draws nothing
g.DrawRectangle(10, 10, 20, 20);             // draws a 2 x 2 pixel
rectangle

Maybe you have to decrease the GDI+ w and h values by 1 in your routines to
make them correspond... Not much of an answer, is it? :-)

Just for curiosity: What's the point mixing?

Regards / Jonas

Quote:> Hi, I am writing a component.

> I do something like the Paint method below.

> The problem is that the two Canvas.Ellipse calls dosn't draw on the same
> place on the canvas, so GDI plus must change the coordinate system
somehow.
> How can I fix this?

> regards,
> David

> procedure TMyControl.Paint;
> var
>   g: TGPGraphics;
>   p: TGPPen;
> begin
>   g := TGPGraphics.Create(Canvas.Handle);
>   p := TGPPen.Create(MakeColor(127, 255, 0, 255));
>   try
>     Canvas.Ellipse(Bounds(10, 10, 20, 20));

>     g.DrawEllipse(10, 10, 20, 20);

>     Canvas.Ellipse(Bounds(10, 10, 20, 20));
>   finally
>     g.Free;
>   end;
> end;

> --
> mvh,
> David

### mixing gdi and gdi+

Sorry for error in code example above. It should be

Quote:> Canvas.Rectangle(Bounds(10, 10, 1, 1));  // draws nothing
> g.DrawRectangle(10, 10, 1, 1);             // draws a 2 x 2 pixel

Regards / Jonas

### mixing gdi and gdi+

Quote:> Maybe you have to decrease the GDI+ w and h values by 1 in your
> routines to make them correspond... Not much of an answer, is it? :-)

Thanks but nope thats not it!

I found the problem, but not the solution.

My control inherites from TGraphicControl, ie it dosn't have its own canvas.
and GDIPlus resets the canvas origin. So everything works as expected when I
interit from TCustomControl instead.  But I don't want to use
TCustomControl, any ideas?

Quote:> Just for curiosity: What's the point mixing?

I am drawing map handling/rendering code wich is based on TCanvas, now I
want to add pransparent polygon objects to the map. So the plan is to use
GDI+ for these objects.

regards,
David

I'm starting with an effort to integrate OpenGL with our project.

On the Windows side, when I use OpenGL to draw into a rectangle in a
window that also has GDI graphics and text being drawn there tho offset
by some pixels so that they don't overlap, scrolling the window content
up and down causes the GDI graphics and text to break up as if it isn't
being updated properly, or updated in the right place. The phenom
appears related to using the SetPixelFormat() command; I'm not using
double buffers as per the MS doc on opengl. Note that there is a bit of
QTML driving some offscreen pixmap copying to the view.

Has anyone seen this sort of behavior?