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 android.graphics.Path but couldn't find anything for UWP.
Android 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;
}
My tried C# Code
public WriteableBitmap getPathBitmap(int width, int height, GraphicsSegment[] segments)
{
List<int> points = new List<int>();
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;
}
GraphicsSegment is a class with properties x,y,x1,y1,x2,y2 corresponding X,Y coordinate position of first, second and third target point