• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipSetLinePresetBlend

Started by José Roca, June 22, 2008, 01:41:50 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca


 
The following example creates a linear gradient brush, sets the colors to be interpolated for the linear gradient brush, and fills a rectangle.

C++


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

   Color colors[] = {
      Color(255, 255, 0, 0),   // red
      Color(255, 0, 0, 255),   // blue
      Color(255, 0, 255, 0)};  // green

   REAL positions[] = {
      0.0f,   // red at the left edge
      0.3f,   // blue at 30 percent of the distance from left edge
              // to right edge
      1.0f};  // green at the right edge

   LinearGradientBrush linGrBrush(
      Point(0, 0),
      Point(100, 0),
      Color(255, 0, 0, 0),         // black
      Color(255, 255, 255, 255));  // white

   linGrBrush.SetInterpolationColors(colors, positions, 3);
   myGraphics.FillRectangle(&linGrBrush, 0, 0, 100, 50);
}


PowerBASIC


SUB GDIP_SetLinePresetBlend (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pLinBrush AS DWORD
   LOCAL colorBlack AS DWORD
   LOCAL colorWhite AS DWORD
   LOCAL pt1 AS POINTF
   LOCAL pt2 AS POINTF
   DIM   blend(2) AS DWORD
   DIM   positions(2) AS SINGLE

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   blend(0) = GDIP_ARGB(255, 255, 0, 0)  ' // red
   blend(1) = GDIP_ARGB(255, 0, 0, 255)  ' // blue
   blend(2) = GDIP_ARGB(255, 0, 255, 0)  ' // green

   positions(0) = 0.0!   ' // red at the left edge
   positions(1) = 0.3!   ' // blue at 30 percent of the distance from left edge to right edge
   positions(2) = 1.0!   ' // green at the right edge

   pt1.x = 0 : pt1.y = 0 : pt2.x = 100 : pt2.y = 0
   colorBlack = GDIP_ARGB(255, 0, 0, 0)
   colorWhite = GDIP_ARGB(255, 255, 255, 255)
   hStatus = GdipCreateLineBrush(pt1, pt2, colorBlack, colorWhite, %WrapModeTile, pLinBrush)

   hStatus = GdipSetLinePresetBlend(pLinBrush, blend(0), positions(0), 3)
   hStatus = GdipFillRectangle(pGraphics, pLinBrush, 0, 0, 100, 50)

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

END SUB