本文整理汇总了C#中Android.Hardware.Camera.SetPreviewCallback方法的典型用法代码示例。如果您正苦于以下问题:C# Camera.SetPreviewCallback方法的具体用法?C# Camera.SetPreviewCallback怎么用?C# Camera.SetPreviewCallback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.Hardware.Camera
的用法示例。
在下文中一共展示了Camera.SetPreviewCallback方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SurfaceCreated
public void SurfaceCreated (ISurfaceHolder holder)
{
try {
camera = Camera.Open ();
camera.SetPreviewDisplay (holder);
camera.SetPreviewCallback (this);
} catch (Exception e) {
ShutdownCamera ();
// TODO: log or otherwise handle this exception
throw;
}
}
示例2: OnSurfaceTextureAvailable
public void OnSurfaceTextureAvailable(Android.Graphics.SurfaceTexture surface, int width, int height)
{
_camera = Camera.Open ();
ConfigureCamera ();
Preview preview = new Preview ();
preview.OnFrame += OnPreviewFrame;
_camera.SetPreviewCallback (preview);
_textureView.LayoutParameters = new FrameLayout.LayoutParams (width, height);
try {
_camera.SetPreviewTexture (surface);
_camera.StartPreview ();
} catch (Exception e) {
Console.WriteLine (e.Message);
}
}
示例3: OnPreviewFrame
public void OnPreviewFrame (byte[] data, Camera camera)
{
var parameters = camera.GetParameters ();
var size = parameters.PreviewSize;
var barcode = new Image (size.Width, size.Height, "Y800");
barcode.SetData (data);
var result = scanner.ScanImage (barcode);
if (result == 0)
return;
camera.SetPreviewCallback (null);
camera.StopPreview ();
var scannerResult = GetScannerResult ();
ScanComplete?.Invoke (this, new ScanCompleteEventArgs (scannerResult));
}
示例4: SurfaceCreated
public void SurfaceCreated (ISurfaceHolder holder)
{
try {
Console.WriteLine("Surface created");
camera = Android.Hardware.Camera.Open ();
camera.SetPreviewDisplay (holder);
camera.SetPreviewCallback (this);
Console.WriteLine("Surface Created end");
} catch (Exception) {
ShutdownCamera ();
Console.WriteLine("Exception, shutdown camera");
// TODO: log or otherwise handle this exception
//throw;
}
}
示例5: SurfaceCreated
public void SurfaceCreated (ISurfaceHolder holder)
{
try
{
#if __ANDROID_9__
var numCameras = Android.Hardware.Camera.NumberOfCameras;
var camInfo = new Android.Hardware.Camera.CameraInfo();
var found = false;
for (int i = 0; i < numCameras; i++)
{
Android.Hardware.Camera.GetCameraInfo(i, camInfo);
if (camInfo.Facing == CameraFacing.Back)
{
camera = Android.Hardware.Camera.Open(i);
found = true;
break;
}
}
if (!found)
{
Android.Util.Log.Debug("ZXing.Net.Mobile", "Finding rear camera failed, opening camera 0...");
camera = Android.Hardware.Camera.Open(0);
}
#else
camera = Android.Hardware.Camera.Open();
#endif
if (camera == null)
Android.Util.Log.Debug("ZXing.Net.Mobile", "Camera is null :(");
//camera = Android.Hardware.Camera.Open ();
camera.SetPreviewDisplay (holder);
camera.SetPreviewCallback (this);
} catch (Exception ex) {
ShutdownCamera ();
// TODO: log or otherwise handle this exception
Console.WriteLine("Setup Error: " + ex);
//throw;
}
}
示例6: CreateCamera
/// <summary>
/// Create the camera and try to set auto focus with flash
/// </summary>
/// <param name="holder"></param>
public void CreateCamera(ISurfaceHolder holder) {
try
{
_camera = Camera.Open();
Camera.Parameters p = _camera.GetParameters();
p.PictureFormat = Android.Graphics.ImageFormatType.Jpeg;
p.JpegQuality = 100;
hasAutoFocus = (p.SupportedFocusModes.Contains(Camera.Parameters.FocusModeAuto));
if (hasAutoFocus)
{
p.FocusMode = Camera.Parameters.FocusModeAuto;
focusReady = true;
}
else if (p.SupportedFocusModes.Contains(Camera.Parameters.FocusModeContinuousPicture))
{
p.FocusMode = Camera.Parameters.FocusModeContinuousPicture;
}
if (p.SupportedFlashModes.Contains(Camera.Parameters.FlashModeOn))
{
p.FlashMode = Camera.Parameters.FlashModeOn;
}
_camera.SetParameters(p);
_camera.SetDisplayOrientation(90);
_camera.SetPreviewCallback(this);
_camera.Lock();
_camera.SetPreviewDisplay(holder);
_camera.StartPreview();
if (hasAutoFocus)
{
Toast.MakeText(this, "Press screen to focus", ToastLength.Long).Show();
}
}
catch (Exception e)
{
}
}