创建 Skiasharp 相机叠加层 Xamarin iOS



我正在尝试创建一个应用程序,该应用程序在iPhone(本机(上相机的叠加层上使用skiasharp。我的相机流显示得很好,但没有叠加。创建流的初始视图控制器如下所示:

public async  override void ViewDidLoad()
{
base.ViewDidLoad();
await AuthorizeCameraUse();
imagePicker = new UIImagePickerController();
// set our source to the camera
imagePicker.SourceType = UIImagePickerControllerSourceType.Camera;
// set
imagePicker.MediaTypes = new string[] { "public.image" };

imagePicker.CameraOverlayView = new CameraOverlayView();
imagePicker.ModalPresentationStyle = UIModalPresentationStyle.CurrentContext;
.   . .

我的相机叠加视图看起来像:

public class CameraOverlayView :SKCanvasView
{
public CameraOverlayView() : base()
{
Initialize();
}
public CameraOverlayView(CGRect frame) : base(frame) {
Initialize();
}
SKPaint paint = new SKPaint
{
Style = SKPaintStyle.Fill,
Color = SKColors.Red,
StrokeWidth = 25
};
protected void Initialize()
{
this.PaintSurface += CameraOverlayView_PaintSurface;
//using (var surface = SKSurface.Create( 640, 480, SKColorType.Rgba8888, SKAlphaType.Premul))
//{
//    SKCanvas myCanvas = surface.Canvas;
//    myCanvas.DrawCircle(300, 300, 100, paint);
//    // Your drawing code goes here.
//}
}
private void CameraOverlayView_PaintSurface(object sender, SKPaintSurfaceEventArgs e)
{
var surface = e.Surface;
// then we get the canvas that we can draw on
var canvas = surface.Canvas;
// clear the canvas / view
canvas.Clear(SKColors.White);

// DRAWING SHAPES
// create the paint for the filled circle
var circleFill = new SKPaint
{
IsAntialias = true,
Style = SKPaintStyle.Fill,
Color = SKColors.Blue
};
// draw the circle fill
canvas.DrawCircle(100, 100, 40, circleFill);
}
}

我的 Paint 事件永远不会被触发,如果我在简单示例中运行此代码,它会触发。

感谢 Russ Fustino 的帮助,事实证明我没有使用CameraOverlayView (CGRect frame) : base (frame)构造函数,因此没有调用DrawInSurface重载。 没什么可吸引的。当我这样做时,油漆事件被触发了。

最新更新