title: Draw Bitmap on Xamarin.Android Canvas
body: <p>I see a lot of examples for android programming in java but very little for Xamarin / C# related. </p>
  
  <p>I'm unable to draw this bitmap on my canvas with the following code (i have highlighted whatever is not working as it should). If something works without a compile-time error, the app stops with a <code>java null object reference</code> while debugging and it seems that the compiler hasn't picked up my <code>green.jpg</code> resource. Everything else seems to work fine. </p>
  
  <p><strong>How can I get a simple drawable to display on canvas?</strong></p>
  
  <pre><code>class MyCanvasPath : Android.Views.View /*extends View*/
  {
      Paint myPaint = new Paint();
      Color myColor = new Color();
      Path myPath = new Path(); //Bitmap bitmap; Resource res;
      private int a,b; 
      //Android.Graphics.Drawables.BitmapDrawable bm;
  
      public MyCanvasPath(Context context) : base(context) //constructor
      {
          //var bitmap = BitmapFactory.DecodeResource(res, Resource.Drawable.green);
          //var bitmap = Bitmap.CreateBitmap(green, 100, 100, 400, 400);
          //var bm = Android.Graphics.Drawables.BitmapDrawable.CreateFromPath("E:\\[project_name]\\Resources\\drawable\\green.jpg");
          int[,] FirstPath; int arrayLength = 0;
          FirstPath = new int[,] { { 200, 350 }, { 70, 80 }, { 90, 40 }, { 10, 40 }, { 50, 80 }, { 0, 350 } };
          arrayLength = FirstPath.Length / 2;
          myPaint.SetARGB(255, 200, 255, 0);
          myPaint.SetStyle(Paint.Style.FillAndStroke);
          myPaint.StrokeWidth = 9;
          myPaint.TextSize = 40;
          myPaint.Color = Color.DarkCyan; //drawing pencil for path lines
          myColor = Color.RosyBrown; //not used for path or text, hmm
          myPath.Reset();
          myPath.MoveTo(FirstPath[0, 0], FirstPath[0, 1]);
          for (int tempint = 1; tempint &lt; arrayLength; tempint++)
          { myPath.LineTo(FirstPath[tempint, 0], FirstPath[tempint, 1]); } 
  
      }//end of constructor for MyCanvasPath
  
      protected override void OnDraw(Canvas canvas)
      {
          canvas.DrawColor(myColor);
          b = canvas.Height; a = canvas.Width;
          canvas.DrawText(b.ToString()+" x "+a.ToString(),10,b-50, myPaint);
          canvas.DrawPath(myPath, myPaint);
          //canvas.SetBitmap(Resource.Drawable.green);
          //canvas.DrawBitmap(bm, 100, 100, null);
          //canvas.DrawBitmap(bitmap,100,100, myPaint);
      }
  }//end of class MyCanvasPath
  </code></pre>