2016-11-30 52 views
2

我正在尝试使用跟随您的手指的眼睛来制作应用程序。 但是,当我加载我的应用程序时,绘图不会出现。 它加载紫色背景很好,但似乎停在那里。 谁能告诉我为什么会发生这种情况?C#绘制不会使绘图

using Android.App; 
using Android.Widget; 
using Android.OS; 
using Android.Graphics; 
using Android.Views; 
using Android.Content; 
using Android.Content.PM; 
using System; 


namespace BewegendeOgen 
{ 
[Activity(Label = "BewegendeOgen", MainLauncher = true, Icon = "@drawable/icon", ScreenOrientation = ScreenOrientation.Landscape)] 
public class MainActivity : Activity 
{ 
    OgenView ogen; 


    protected override void OnCreate(Bundle bundle) 
    { 
     base.OnCreate(bundle); 
     ogen = new OgenView(this); 


     this.SetContentView(ogen); 
    } 
} 

public class OgenView : View 

{ 
    public OgenView(Context c) : base(c) 
    { this.Touch += RaakAan; 
     this.SetBackgroundColor(Color.Purple); 

    } 

    PointF punt; 
    public void RaakAan(object o, TouchEventArgs tea) 
    { 
    float xas = tea.Event.GetX(); 
    float yas = tea.Event.GetY(); 
     this.punt = new PointF(xas, yas); 
     this.Invalidate(); 

     this.Invalidate(); 
    } 


protected override void OnDraw(Canvas canvas) 
    { 
     base.OnDraw(canvas); 

     this.tekenoog(canvas, 200); 
     this.tekenoog(canvas, -200); 


    } 

    public void tekenoog(Canvas canvas, int a) 
    { //this is the drawing 
     base.OnDraw(canvas); 
     float radius, x1, x2, y; 
     radius = 200; 
     x1 = this.Width/3; 
     y = this.Height/2; 
     x2 = x1 * 2; 

     Paint verf; 
     verf = new Paint(); 

     verf.Color = Color.White; 
     canvas.DrawCircle(x1 + a, y, radius, verf); 


     float dx, g, e, f, d, ex, ey, radiusiris, irisx1, irisy1; 
     dx = punt.X - x1; 
     g = punt.Y - y; 
     radiusiris = 20; 
     e = radius - radiusiris; 
     f = (float)Math.Sqrt(dx * dx + g * g); 
     d = f - e; 
     ex = dx * e/d; 
     ey = (float)Math.Sqrt(e * e - ex * ex); 
     irisx1 = x1 + ex; 
     irisy1 = y - ey; 

     verf.Color = Color.CornflowerBlue; 
     canvas.DrawCircle(irisx1, irisy1, radiusiris, verf); 
    } 
} 
} 
+0

这是使用xamarin?如果是这样的话,可以更新问题和标签以反映这一点。 – pulekies

回答

0

你永远不会初始化punt,所以当它第一次尝试访问它tekenoog它抛出异常。

我想这在我的机器,它的工作我修改了punt声明后:

private PointF punt = new PointF(); 

希望这有助于!

enter image description here