• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipScaleLineTransform

Started by José Roca, June 22, 2008, 01:57:16 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 modifies the brush's transformation matrix, applying a composite transformation, and then fills a rectangle with the transformed brush.

C++


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

   LinearGradientBrush linGrBrush(
      Rect(0, 0, 80, 40),
      Color(255, 255, 0, 0),  // red
      Color(255, 0, 0, 255),  // blue
      LinearGradientModeHorizontal);

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

   // Apply a composite transformation: first translate, then scale.
   linGrBrush.TranslateTransform(60, 0);            // horizontal translation
   linGrBrush.ScaleTransform(2, MatrixOrderAppend); // horizontal doubling

   // Fill a large area with the transformed linear gradient brush.
   myGraphics.FillRectangle(&linGrBrush, 0, 200, 800, 150); 
}


PowerBASIC


SUB GDIP_ScaleLineTransform (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

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   rc.x = 0 : rc.y = 0 : rc.Width = 80 : rc.Height = 40
   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 using the gradient brush with the default wrap mode.
   hStatus = GdipFillRectangle(pGraphics, pLinBrush, 0, 0, 800, 150)

   ' // Apply a composite transformation: first translate, then scale.
   hStatus = GdipTranslateLineTransform(pLinBrush, 60, 0, %MatrixOrderPrepend)  ' // horizontal translation
   hStatus = GdipScaleLineTransform(pLinBrush, 2, 1, %MatrixOrderAppend)        ' // horizontal doubling

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

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

END SUB