title: Drawing Graphics from Path in UWP C#
body: <p>I'm trying to convert an android method to draw any types of shape. Following are android code and my tried C# code. My C# code doesn't work at all, it gives ambiguous drawing as output.
  I searched a lot about path drawing in C# UWP similar of <strong>android.graphics.Path</strong> but couldn't find anything for UWP.</p>
  
  <p><strong>Android Code</strong></p>
  
  <pre><code>public static Bitmap getPathBitmap(int width, int height, GraphicsSegment[] segments) {
  
      RectF rect = null;
      Path path = new Path();
      Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
      Canvas canvas = new Canvas(bitmap);
      Paint paint = new Paint();
      paint.setStyle(Paint.Style.FILL);
      paint.setColor(Color.TRANSPARENT);
      canvas.drawPaint(paint);
  
      for (GraphicsSegment segment : segments) {
  
          switch (segment.drawingType) {
              case GraphicsSegment.T_MOVETO:
                  path.moveTo(segment.x, segment.y);
                  break;
              case GraphicsSegment.T_LINETO:
                  path.lineTo(segment.x, segment.y);
                  break;
              case GraphicsSegment.T_QUADTO:
                  path.quadTo(segment.x, segment.y, segment.x2, segment.y2);
                  break;
              case GraphicsSegment.T_CUBICTO:
                  path.cubicTo(segment.x, segment.y, segment.x1, segment.y1, segment.x2, segment.y2);
                  break;
              case GraphicsSegment.T_ARCTO:
                  rect = new RectF();
                  rect.set(segment.x, segment.y, segment.x1, segment.y1);
                  path.arcTo(rect, segment.x2, segment.y2, true);
                  break;
              case GraphicsSegment.T_ADDOVAL:
                  rect = new RectF();
                  rect.set(segment.x, segment.y, segment.x1, segment.y1);
                  path.addOval(rect, Path.Direction.CW);
                  break;
              case GraphicsSegment.T_CLOSE:
                  path.close();
                  break;
          }
      }
  
      paint.setStrokeWidth(2);
      paint.setStyle(Paint.Style.STROKE);
      canvas.drawPath(path, paint);
      return bitmap;
  }
  </code></pre>
  
  <p><strong>My tried C# Code</strong></p>
  
  <pre><code> public WriteableBitmap getPathBitmap(int width, int height, GraphicsSegment[] segments)
   {
          List&lt;int&gt; points = new List&lt;int&gt;();
  
          foreach (GraphicsSegment segment in segments)
          {
              if (segment.drawingType == GraphicsSegment.T_CLOSE)
                  continue;
  
              points.Add((int)segment.X);
              points.Add((int)segment.Y);
          }
  
          WriteableBitmap writeableBmp = BitmapFactory.New(width, height);
          using (writeableBmp.GetBitmapContext())
          {
             writeableBmp.DrawPolyline(points.ToArray(), Colors.Blue);
          }
  
          return writeableBmp;
   }
  </code></pre>
  
  <p>GraphicsSegment is a class with properties x,y,x1,y1,x2,y2 corresponding X,Y coordinate position of first, second and third target point</p>