本文整理汇总了C#中Android.Hardware.Camera.StartPreview方法的典型用法代码示例。如果您正苦于以下问题:C# Camera.StartPreview方法的具体用法?C# Camera.StartPreview怎么用?C# Camera.StartPreview使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.Hardware.Camera
的用法示例。
在下文中一共展示了Camera.StartPreview方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StartPreview
protected sealed override void StartPreview()
{
_camera = Camera.Open((int)CurrentCamera);
_camera.SetDisplayOrientation(90);
var parameters = _camera.GetParameters();
if (parameters.SupportedFocusModes.Contains(Camera.Parameters.FocusModeContinuousPicture))
{
parameters.FocusMode = Camera.Parameters.FocusModeContinuousPicture;
}
var optimalSize = GetOptimalPreviewSize(_width, _height);
if (optimalSize != null)
{
parameters.SetPreviewSize(optimalSize.Width, optimalSize.Height);
}
_camera.SetParameters(parameters);
try
{
_camera.SetPreviewTexture(_surface);
_camera.StartPreview();
}
catch (Java.IO.IOException ex)
{
Console.WriteLine(ex.Message);
}
}
示例2: OnSurfaceTextureAvailable
public void OnSurfaceTextureAvailable (Android.Graphics.SurfaceTexture surface, int w, int h)
{
_camera = Camera.Open ();
_textureView.LayoutParameters = new FrameLayout.LayoutParams (w, h);
try {
_camera.SetPreviewTexture (surface);
_camera.StartPreview ();
} catch (Java.IO.IOException ex) {
Console.WriteLine (ex.Message);
}
}
示例3: Liga
public bool Liga()
{
if (TemFlash)
{
camera = Camera.Open();
var parametros = camera.GetParameters();
parametros.FlashMode = Camera.Parameters.FlashModeTorch;
camera.SetParameters(parametros);
camera.StartPreview();
return true;
}
return false;
}
示例4: OnSurfaceTextureAvailable
public void OnSurfaceTextureAvailable(Android.Graphics.SurfaceTexture surface, int width, int height)
{
// var camInfo = new Camera.CameraInfo();
_camera = Camera.Open(0);
// _camera = Camera.Open();
_textureView.LayoutParameters = new FrameLayout.LayoutParams(width, height);
try
{
_camera.SetPreviewTexture(surface);
_camera.StartPreview();
}
catch (Java.IO.IOException ex)
{
Console.WriteLine(ex.Message);
}
}
示例5: OnSurfaceTextureAvailable
public void OnSurfaceTextureAvailable (Android.Graphics.SurfaceTexture surface, int width, int height)
{
_camera = Camera.Open ();
var previewSize = _camera.GetParameters ().PreviewSize;
_textureView.LayoutParameters =
new FrameLayout.LayoutParams (previewSize.Width, previewSize.Height, (int)GravityFlags.Center);
try {
_camera.SetPreviewTexture (surface);
_camera.StartPreview ();
} catch (Java.IO.IOException ex) {
Console.WriteLine (ex.Message);
}
// this is the sort of thing TextureView enables
_textureView.Rotation = 45.0f;
_textureView.Alpha = 0.5f;
}
示例6: 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);
}
}
示例7: OnOptionsItemSelected
public override bool OnOptionsItemSelected(IMenuItem item)
{
// Handle item selection
switch (item.ItemId) {
case Resource.Id.switch_cam:
// Release this camera -> mCameraCurrentlyLocked
if (mCamera != null) {
mCamera.StopPreview ();
mPreview.SetCamera (null);
mCamera.Release ();
mCamera = null;
}
// Acquire the next camera and request Preview to reconfigure
// parameters.
mCamera = Camera.Open ((mCameraCurrentlyLocked + 1) % mNumberOfCameras);
mCameraCurrentlyLocked = (mCameraCurrentlyLocked + 1)
% mNumberOfCameras;
mPreview.SwitchCamera (mCamera);
// Start the preview
mCamera.StartPreview();
return true;
case Android.Resource.Id.Home:
Intent intent = new Intent (this.Activity, typeof (MainActivity));
intent.AddFlags (ActivityFlags.ClearTop | ActivityFlags.SingleTop);
StartActivity (intent);
goto default;
default:
return base.OnOptionsItemSelected (item);
}
}
示例8: SurfaceChanged
public void SurfaceChanged(ISurfaceHolder holder, [GeneratedEnum] Format format, int width, int height)
{
//var parameters = camera.GetParameters();
//parameters.SetPreviewSize(width, height);
//IList<Android.Hardware.Camera.Size> vSizeList = parameters.SupportedPictureSizes;
//for (int num = 0; num < vSizeList.Count; num++)
//{
// var vSize = vSizeList[num];
//}
if (this.Resources.Configuration.Orientation != Android.Content.Res.Orientation.Landscape)
{
camera.SetDisplayOrientation(90);
}
else
{
camera.SetDisplayOrientation(0);
}
//camera.SetParameters(parameters);
try
{
camera.SetPreviewDisplay(holder);
}
catch (Exception exception)
{
camera.Release();
camera = null;
}
camera.StartPreview();
//�Զ��Խ�
//camera.AutoFocus(this);
}
示例9: 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)
{
}
}
示例10: StartPreview
private bool StartPreview(Camera camera)
{
if (camera == null) { return false; }
StopPreview(camera);
// Mark preview as started if surface holder not yet created. We will really start it later
_previewStarted = true;
if (_surfaceHolder == null) { return false; }
camera.SetDisplayOrientation(_displayOrientation);
camera.SetPreviewDisplay(_surfaceHolder);
try { camera.StartPreview(); }
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("StartPreview {0}", ex);
return false;
}
return true;
}
示例11: OnOptionsItemSelected
public override bool OnOptionsItemSelected (IMenuItem item)
{
// Handle item selection
switch (item.ItemId) {
case Resource.Id.switch_cam:
// check for availability of multiple cameras
if (numberOfCameras == 1) {
AlertDialog.Builder builder = new AlertDialog.Builder (this);
builder.SetMessage (GetString (Resource.String.camera_alert))
.SetNeutralButton ("Close", (Android.Content.IDialogInterfaceOnClickListener)null);
AlertDialog alert = builder.Create ();
alert.Show ();
return true;
}
// OK, we have multiple cameras.
// Release this camera -> cameraCurrentlyLocked
if (mCamera != null) {
mCamera.StopPreview ();
mPreview.PreviewCamera = null;
mCamera.Release ();
mCamera = null;
}
// Acquire the next camera and request Preview to reconfigure
// parameters.
mCamera = Camera.Open ((cameraCurrentlyLocked + 1) % numberOfCameras);
cameraCurrentlyLocked = (cameraCurrentlyLocked + 1) % numberOfCameras;
mPreview.SwitchCamera (mCamera);
// Start the preview
mCamera.StartPreview ();
return true;
default:
return base.OnOptionsItemSelected (item);
}
}