uses Direct2D, D2D1; const penWidth = 25; var iGeometry: ID2D1EllipseGeometry; procedure TForm1.FormCreate(Sender: TObject); begin D2DFactory.CreateEllipseGeometry(D2D1Ellipse(D2D1PointF(120, 90), 80, 50), iGeometry); end; procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); var bFill, bStroke: LongBool; intBool: Integer; str: string; begin iGeometry.FillContainsPoint(Point(X,Y), TD2DMatrix3x2F.Identity, 0, bFill); iGeometry.StrokeContainsPoint(Point(X,Y), penWidth, nil, TD2DMatrix3x2F.Identity, 0, bStroke); intBool := 0; Inc(intBool, Integer(bFill) shl 1); Inc(intBool, Integer(bStroke) shl 2); case intBool of 0: str := '无命中'; 2: str := '命中椭圆'; 4: str := '命中椭圆边缘'; 6: str := '同时命中椭圆及边缘'; end; Caption := str; end; procedure TForm1.FormPaint(Sender: TObject); var cvs: TDirect2DCanvas; begin cvs := TDirect2DCanvas.Create(Canvas, ClientRect); cvs.BeginDraw; cvs.Brush.Color := clYellow; cvs.FillGeometry(iGeometry); cvs.Pen.Color := clRed; cvs.Pen.Brush.Handle.SetOpacity(0.5); cvs.Pen.Width := penWidth; cvs.DrawGeometry(iGeometry); cvs.Pen.Brush.Handle.SetOpacity(1); cvs.Pen.Width := 1; cvs.DrawGeometry(iGeometry); cvs.EndDraw; cvs.Free; end;
效果图: