• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipGetPenCompoundArray

Started by José Roca, July 02, 2008, 02:17:33 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example declares an array, sets the compound array, draws a line, and gets the elements in the compound array.

C++


VOID Example_GetCompoundArray(HDC hdc)
{
   Graphics graphics(hdc);

   REAL compVals[6] = {0.0f, 0.2f, 0.5f, 0.7f, 0.9f, 1.0f};
   Pen pen(Color(255, 0, 0, 0), 30);
   pen.SetCompoundArray(compVals, 6);
   graphics.DrawLine(&pen, 5, 20, 405, 200);

   // Obtain information about the pen.
   INT count = 0;
   REAL* compValues = NULL;

   count = pen.GetCompoundArrayCount();
   compValues = (REAL*)malloc(count*sizeof(REAL));
   pen.GetCompoundArray(compValues, count);

   TraceInt(count);
   for(INT j = 0; j < count; ++j)

   {
      // Inspect or use the value in compValues[j].
   }
}


PowerBASIC


SUB GDIP_GetPenCompoundArray (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pPen AS DWORD

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   ' // Create an array of real numbers and a Pen object.
   DIM compVals(5) AS SINGLE
   ARRAY ASSIGN compVals() = 0.0!, 0.2!, 0.5!, 0.7!, 0.9!, 1.0!
   hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 0, 255), 30, %UnitWorld, pPen)

   ' // Set the compound array of the pen.
   hStatus = GdipSetPenCompoundArray(pPen, compVals(0), 6)

   ' // Draw a line with the pen.
   hStatus = GdipDrawLineI(pGraphics, pPen, 5, 20, 405, 200)

   ' // Obtain information about the pen.
   LOCAL count AS LONG
   DIM   compValues(0) AS SINGLE

   hStatus = GdipGetPenCompoundCount(pPen, count)
   REDIM compValues(count - 1)
   hStatus = GdipGetPenCompoundArray(pPen, compValues(0), count)

   LOCAL j AS LONG
   FOR j = 0 TO count - 1
      ' // Inspect or use the value in compValues[j].
   NEXT

   ' // Cleanup
   IF pPen THEN GdipDeletePen(pPen)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB