Does rotation not affect GetPath?

I am using Delphi (XE5) to create a graphical component. One of the tasks is to rotate the closed path using SetWorldTransform, and then read the diagram using GetPath. The rotation works fine, but the points obtained from GetPath are not rotating (however traversing the region (PathToRegion) works as expected!).

My code:

procedure Rotate(DestBitmap : TBitmapEx; Radians : Single;  FigureRect : TRect);

// DestBitmap is where to draw the figure. Size of DestBitmap is computed from
//the actual angle and figure size (not shown here). FigureRect is the plain
//figure rectangle without rotation

var
  XForm: tagXFORM;
  C, S : single;
  Points : array of TPoint;
  NumPoints : integer;
  Bytes : TByteArray;
  Rgn : HRGN;
  X, Y : integer;

 begin
  //Locate FigureRect to center of bitmap: 
  X := (DestBitmap.Width - FigureRect.Width) div 2;
  Y := (DestBitmap.Height - FigureRect.Height) div 2;
  FigureRect.Location := Point(X,Y);

  //Set rotate mode 
  C := Cos(Radians);
  S := Sin(Radians);
  XForm.eM11 := C;
  XForm.eM12 := S;
  XForm.eM21 := -S;
  XForm.eM22 := C;
  XForm.eDx := (DestBitmap.Width - DestBitmap.Width * C +
    DestBitmap.Height * S) / 2;
  XForm.eDy := (DestBitmap.Height - DestBitmap.Width * S -
    DestBitmap.Height * C) / 2;
  SetGraphicsMode(DestBitmap.Canvas.Handle, GM_ADVANCED);
  SetWorldTransform(DestBitmap.Canvas.Handle, XForm);

  //Rotate the figure
  BeginPath(DestBitmap.Canvas.Handle);
  DestBitmap.Canvas.Rectangle(FigureRect);
  EndPath(DestBitmap.Canvas.Handle);
  FlattenPath(DestBitmap.Canvas.Handle);
  NumPoints := GetPath(DestBitmap.Canvas.Handle, Points[0], Bytes[0], 0);
  SetLength(Points, NumPoints);
  GetPath(DestBitmap.Canvas.Handle, Points[0], Bytes[0], NumPoints);

  //Points now describes the plain, unrotated figure, but if instead:
  //Rgn := PathToRegion(DestBitmap.Canvas.Handle);
  //Rgn describes the rotated area, as expected 
end;

      

+3


source to share


1 answer


It is expected to GetPath

return points in logical coordinates. Whereas, the resulting area PathToRegion

uses device coordinates - so it is not affected by the transformation. See the documentation for both functions.



Or three, SetWorldTransform

converts to logical coordinates. For everything in the logical world, nothing has changed. The conversion is device specific.

+2


source







All Articles