2016-11-30 79 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