【发布时间】:2021-09-22 12:36:13
【问题描述】:
我按照这个Blog 在我的相机预览中添加了叠加视图。
在后台打开Camera Preview,在它的顶部有覆盖的外部矩形(紫红色)和内部的圆形。
有两种形状圆形和心形。我想添加椭圆形。
我添加了椭圆形,但没有用。
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
}
【问题讨论】:
标签: c# .net xamarin xamarin.forms