简体   繁体   中英

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). My camera stream appears nicely but no overlay. the initial viewcontroller that creates the stream looks like:

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:

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.

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. Nothing to draw into. when I did this the paint event fired.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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