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

  • How to Do Machine Learning Evolutionary Optimization Using C#

    Resident data scientist Dr. James McCaffrey of Microsoft Research turns his attention to evolutionary optimization, using a full code download, screenshots and graphics to explain this machine learning technique used to train many types of models by modeling the biological processes of natural selection, evolution, and mutation.

  • Old Stone Wall Graphic

    Visual Studio Code Boosts Java Dependency Viewer

    Easier management of project code dependencies and improvements to extensions for popular Java frameworks and runtimes highlight the February update to Java in Visual Studio Code functionality.

  • Blule Squares

    Visual Studio 2019 for Mac 8.5 Preview Adds ASP.NET Core Authentication

    Microsoft, after shipping Visual Studio 2019 for Mac v8.4 with support for ASP.NET Core Blazor Server applications last month, is now previewing the v8.5 series, adding new authentication templates for ASP.NET Core along with other improvements.

  • Q&A with Brice Wilson: What's New in Angular 9

    We caught up with expert web developer/trainer Brice Wilson to get his take on Angular, which always appears at or near the top of periodic rankings of the most popular JavaScript-based web development frameworks.

  • Entity Framework Core Migrations

    Eric Vogel uses code samples and screenshots to demonstrate how to use Entity Framework Core migrations in a .NET Core application through the command line and in code.

.NET Insight

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.

Upcoming Events