简体   繁体   English

创建Skiasharp相机覆盖Xamarin iOS

[英]create skiasharp camera overlay xamarin ios

I am trying to create a app that uses skiasharp on an overlay for the camera on iPhone (native). 我正在尝试创建一个在iPhone(本机)上为摄像头的覆盖层上使用skiasharp的应用。 My camera stream appears nicely but no overlay. 我的相机流看起来不错,但没有覆盖。 the initial viewcontroller that creates the stream looks like: 创建流的初始viewcontroller如下所示:

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;
      .   . .

my CameraOverlayView looks like: 我的CameraOverlayView看起来像:

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);
    }
}

my Paint event is never fired , if I run this code in simple example it does. 如果我在简单的示例中运行此代码,则不会触发我的Paint事件。

thanks to Russ Fustino help it turns out I was not using the CameraOverlayView (CGRect frame) : base (frame) constructor and because of that the DrawInSurface overload is not called. 感谢Russ Fustino的帮助,事实证明我没有使用CameraOverlayView (CGRect frame) : base (frame)构造函数,因此未调用DrawInSurface重载。 Nothing to draw into. 没什么可吸引的。 when I did this the paint event fired. 当我这样做时,触发了绘画事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM