I followed this Blog to add Overlay View on my Camera Preview.
In background, Camera Preview is opened, and on the top of it there is overlay outer rectangle (in Fuchsia color) and circle shape inside.
There are two shapes Circle & Heart. I want to add Oval.
I added Oval, but it didn't worked.
OverlayView.cs
public enum OverlayShape
{
Circle,
Heart,
Oval
}
public static readonly BindableProperty ShapeProperty = BindableProperty.Create(
propertyName: nameof(Shape),
returnType: typeof(CameraOverlayShape),
declaringType: typeof(CameraOverlayView),
defaultValue: CameraOverlayShape.Oval,
defaultBindingMode: BindingMode.TwoWay);
NativeOverlayView.cs
OverlayShape overlayShape = OverlayShape.Oval;
public OverlayShape Shape
{
get { return overlayShape; }
set
{
overlayShape = value;
Redraw();
}
}
Paint paint = new Paint(PaintFlags.AntiAlias)
{
Color = OverlayBackgroundColor,
Alpha = (int)(255 * Opacity)
};
RectF outerRectangle = new RectF(0, 0, width, height);
osCanvas.DrawRect(outerRectangle, paint);
switch (Shape)
{
case OverlayShape.Oval:
osCanvas.DrawOval(outerRectangle, paint);
break;
default:
// Code
}
The following code works on my side .
case OverlayShape.Oval:
shapeHeight = (float)(shapeHeight * 0.8);
RectF rect = new RectF(width / 2- shapeWidth / 2, height / 2 - shapeHeight / 2, shapeWidth/2+ width/2 , shapeHeight/2+height/2);
osCanvas.DrawOval(rect, paint);
break;