Board index » delphi » 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

 

Re: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

"David" <davidsl...@hotmail.com> skrev i meddelandet
news:3ee04db6$1@newsgroups.borland.com...

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

Re: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

Re: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

Other Threads