2017-08-15 67 views
0

我想创建一个应用程序,它在iPhone(本机)上的摄像头覆盖层上使用skiasharp。我的相机流很好地显示,但没有覆盖。创建该流的初始视图 - 控制的样子:创建skiasharp摄像头覆盖图xamarin ios

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

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

我的Paint事件从来没有发射,如果我在运行简单的例子,它的代码。

回答

0

感谢Russ Fustino帮助它证明我没有使用CameraOverlayView (CGRect frame) : base (frame)构造函数,并且因为DrawInSurface超载没有被调用。 没有什么可以借鉴的。当我这样做时,绘画事件开始了。