This article provides the following information:

Regions are no longer bound to device coordinates and are subject to coordinate transformations.

It does not work. Who can used this functionality? I just like in the first GDI it turns out to turn the canvas entirely. How to apply coordinate transformations to the region?

    2 answers 2

    Regions: unlike GDI, regions are no longer tied to device coordinates and are subject to coordinate transformations

    This is a strange maxim. In GDI, regions work in logical coordinates (page coordinate system, logical pixels), and not in device coordinates. And they are undergoing global transformations. Example:

    var hr: HRGN; xf: XFOrm; begin xf.eM11 := 0.87; xf.eM12 := -0.5; xf.eM21 := 0.5; xf.eM22 := 0.87; xf.eDx := -50; xf.eDy := 50; SetGraphicsMode(Canvas.Handle, GM_ADVANCED); SetWorldTransform(Canvas.Handle, xf); hr := CreateRectRgn(120, 120, 220, 220); Canvas.Brush.Color := clGreen; FillRgn(Canvas.Handle, hr, Canvas.Brush.Handle); 

    Be that as it may, a phrase подчиняются координатным преобразованиям does not mean that the transformation matrix applies only to the selected region.

    Perhaps the desired effect can be achieved using the clipping region.

    • "does not mean that the transformation matrix applies only to the selected region." It’s a pity, for some reason I understood this exactly this way ... I would like to apply the transformation matrix to a specific region. About the region of the cut-off must go read, never heard. If there is an opportunity to give an example, I will be grateful - Isaev
    • SetClipRgn (...) - MBo
    • And you can not draw a region on a separate canvas with its own transformations, and then copy it to the right place? - kot-da-vinci
    • @ kot-da-vinci Probably possible. However, to copy a region (it is his environment), you need to set it as a clipping region, so it’s easier to do everything on the right canvas (if you don’t pursue other goals) - MBo
    • @MBo, thanks for the tip, pokladuyu at leisure, accomplish your goal - Isaev

    A simple example on the example of geometric paths (Path), working with regions is absolutely similar:

     Const PolyPoints: Array[0..8] Of TGPPoint = ((x: 50 ; y: 50 ), (x: 100 ; y: 50 ), (x: 150 ; y: 100 ), (x: 100 ; y: 150 ), (x: 150 ; y: 200 ), (x: 100 ; y: 250 ), (x: 150 ; y: 300 ), (x: 100 ; y: 350 ), (x: 50 ; y: 350)); Cnt = 45; Var I: Integer; FGDIPlus: TGPGraphics; Pen: TGPPen; Path: TGPGraphicsPath; solidBrush: TGPSolidBrush; RMatr, TMatr: TGPMatrix; Begin FBitmap.SetSize(Width, Height); FGDIPlus := TGPGraphics.Create(FBitmap.Canvas.Handle); // Pen := TGPPen.Create(TGPColor.Create(255, 0, 0, 0), 1 / FGDIPlus.GetDpiX); Path := TGPGraphicsPath.Create; Path.AddPolygon(PolyPoints); TMatr := TGPMatrix.Create; TMatr.Translate(Width / 2, Height / 2); TMatr.Scale(-0.5, -0.5); Path.Transform(TMatr); RMatr := TGPMatrix.Create; RMatr.RotateAt(360 / Cnt, TGPPointF.Create(Width / 2, Height / 2)); For I := 0 To Cnt Do Begin solidBrush := TGPSolidBrush.Create(TGPColor.Create(255 - I * (255 Div Cnt), 255 - I * (255 Div Cnt), I * (255 Div Cnt), 0)); FGDIPlus.FillPath(SolidBrush, Path); FGDIPlus.DrawPath(Pen, Path); solidBrush.Free; // Rgn.Transform(RMatr); Path.Transform(RMatr); End; RMatr.Free; TMatr.Free; Path.Free; Pen.Free; End; 
    • And what does it mean - "working with the regions is absolutely similar"? Are the coordinates of the regions themselves transformed, or is everything that is drawn inside them transformed? - MBo
    • @MBo, the first one works exactly. The second one may also be possible, but I don’t know yet how - Isaev