Plug in to Mono for Android for Lights, Camera and Video Apps: Listing 4

Code for previewing and displaying content.

private void CreateCamera(ISurfaceHolder holder)
{
  try
  {
    if (holder != null)
    { 
      camera = Android.Hardware.Camera.Open();
      Android.Hardware.Camera.Parameters p = camera.GetParameters();
      p.PictureFormat = (int) Format.Jpeg;
      camera.SetParameters(p);
      camera.SetPreviewCallback(this);
      camera.Lock();
      camera.SetPreviewDisplay(holder);
      camera.StartPreview();
                    
      if (PackageManager.HasSystemFeature("android.hardware.camera.autofocus"))
      {
        camera.AutoFocus(this);
      }
    }
  }
  catch (System.Exception e)
  {
    Android.Util.Log.Debug("SIMPLECAMERA", e.Message);
    Console.WriteLine(e.Message);
  }
}

About the Author

Wallace (Wally) B. McClure has authored books on iPhone programming with Mono/Monotouch, Android programming with Mono for Android, application architecture, ADO.NET, SQL Server and AJAX. He's a Microsoft MVP, an ASPInsider and a partner at Scalable Development Inc. He maintains a blog, and can be followed on Twitter.

comments powered by Disqus

Featured

Subscribe on YouTube