• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipResetLineTransform

Started by José Roca, June 22, 2008, 02:11:29 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example creates a linear gradient brush and uses it to fill a rectangle. Next, the code sets the brush's transformation matrix, fills a rectangle with the transformed brush, resets the brush's transformation matrix, and fills a rectangle with the untransformed brush.

C++


VOID Example_ResetTrans(HDC hdc)
{
   Graphics myGraphics(hdc);

   Matrix S(2, 0, 0, 1, 0, 0);   // horizontal doubling

   LinearGradientBrush linGrBrush(
      Rect(0, 0, 200, 100),
      Color(255, 255, 0, 0),  // red
      Color(255, 0, 0, 255),  // blue
      LinearGradientModeHorizontal);

   // Fill a large area with the gradient brush (no transformation).
   myGraphics.FillRectangle(&linGrBrush, 0, 0, 800, 100);

   // Apply the scaling transformation.
   linGrBrush.SetTransform(&S);

   // Fill a large area with the scaled gradient brush.
   myGraphics.FillRectangle(&linGrBrush, 0, 150, 800, 100);

   // Reset the transformation.
   linGrBrush.ResetTransform();

   // Fill a large area with the gradient brush (no transformation).
   myGraphics.FillRectangle(&linGrBrush, 0, 300, 800, 100);
}


PowerBASIC


SUB GDIP_ResetLineTransform (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pLinBrush AS DWORD
   LOCAL rc AS RECTF
   LOCAL colorRed AS DWORD
   LOCAL colorBlue AS DWORD
   LOCAL S AS DWORD

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   hStatus = GdipCreateMatrix2(2, 0, 0, 1, 0, 0, S)    ' // horizontal doubling

   rc.x = 0 : rc.y = 0 : rc.Width = 200 : rc.Height = 100
   colorRed = GDIP_ARGB(255, 255, 0, 0)
   colorBlue = GDIP_ARGB(255, 0, 0, 255)
   hStatus = GdipCreateLineBrushFromRect(rc, colorRed, colorBlue, %LinearGradientModeHorizontal, %WrapModeTile, pLinBrush)

   ' // Fill a large area with the gradient brush (no transformation).
   hStatus = GdipFillRectangle(pGraphics, pLinBrush, 0, 0, 800, 100)

   ' // Apply the scaling transformation.
   hStatus = GdipSetLineTransform(pLinBrush, S)

   ' // Fill a large area with the scaled gradient brush.
   hStatus = GdipFillRectangle(pGraphics, pLinBrush, 0, 150, 800, 100)

   ' // Reset the transformation.
   hStatus = GdipResetLineTransform(pLinBrush)

   ' // Fill a large area with the gradient brush (no transformation).
   hStatus = GdipFillRectangle(pGraphics, pLinBrush, 0, 300, 800, 100)

   ' // Cleanup
   IF S THEN GdipDeleteMatrix(S)
   IF pLinBrush THEN GdipDeleteBrush(pLinBrush)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB