Einzelnen Beitrag anzeigen

Benutzerbild von Bummi
Bummi

Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
 
Delphi XE3 Enterprise
 
#4

AW: GDI+ und AntiAliasing: mal geht' s, mal nicht

  Alt 3. Mai 2012, 07:57
Clipping ist "böse" und lässt sich vermeiden:
Delphi-Quellcode:
procedure TForm2.DrawGradiantEllipse(Handle: HDC; X, Y, Width, Height,
  RingWidth: integer; OuterColor, InnerColor: cardinal; UseGradient: boolean);
var
  g: TGPGraphics;
  pBrush: TGPPathGradientBrush;
  region,region2: TGPRegion;
  pen: TGPPen;
  OuterRect: TGPRect;
  InnerRect: TGPRect;
  InnerPath: TGPGraphicsPath;
  OuterPath: TGPGraphicsPath;
  Count: integer;
  white:cardinal;
  FocusScale: double;
begin
  g := TGPGraphics.Create(Handle);
  region := TGPRegion.Create;
  pBrush := TGPPathGradientBrush.Create;
  pen := TGPPen.Create(OuterColor, RingWidth);
  try
    FocusScale := 1 - (RingWidth / Width);
    g.SetSmoothingMode(SmoothingModeHighQuality);//(SmoothingModeAntiAlias);
    if UseGradient then
    begin
      // Create Outer/Inner Rect
      OuterRect := MakeRect(x,y,Width,Height);
      InnerRect := MakeRect(OuterRect.X + RingWidth div 2,
                            OuterRect.Y + RingWidth div 2,
                            OuterRect.Width - RingWidth,
                            OuterRect.Height - RingWidth);
      // Create Outer/Inner Ellipse Path
      InnerPath := TGPGraphicsPath.Create;
      OuterPath := TGPGraphicsPath.Create;
      InnerPath.AddEllipse(InnerRect);
      OuterPath.AddEllipse(OuterRect);
      // Create PathGradientBrush
      pBrush := TGPPathGradientBrush.Create(OuterPath);
      pBrush.SetCenterColor(InnerColor);
      // Always a single Color
      count := 1;
      pBrush.SetSurroundColors(@OuterColor,count);
      pBrush.SetFocusScales(FocusScale,FocusScale);
      pBrush.SetBlendTriangularShape(0.5,FocusScale);
      // Create Region of InnerPath
      region := TGPRegion.Create(OuterPath);
      region2 := TGPRegion.Create(InnerPath);
      region.Exclude(region2);
      // "Erases" the Inner Ellipse
     // g.SetClip(region,CombineModeExclude);
      //g.FillEllipse(pBrush,OuterRect);
      g.FillRegion(pbrush,region);
      // Set PenWidth for Ellipse with AA
      pen.SetWidth(1);
    // pen.SetColor(MakeColor(225,0,255,0)); // Just for Debug
      g.DrawEllipse(pen,x + Ringwidth div 2,y + Ringwidth div 2,Width - Ringwidth,Height - Ringwidth);
    end;
    pen.SetColor(MakeColor(225,255,0,0)); // Just for Debug
    g.DrawEllipse(pen,x,y,Width,Height);
  finally
    region.Free;
    region2.Free;
    pBrush.Free;
    g.Free;
    pen.Free;
  end;
end;
Thomas Wassermann H₂♂
Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)
  Mit Zitat antworten Zitat