本文整理汇总了C#中Android.Hardware.Camera类的典型用法代码示例。如果您正苦于以下问题:C# Camera类的具体用法?C# Camera怎么用?C# Camera使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Camera类属于Android.Hardware命名空间,在下文中一共展示了Camera类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StartPreview
public void StartPreview()
{
try
{
var numberOfCameras = Camera.NumberOfCameras;
int? rearFacingCameraId = null;
// Find the ID of the default camera
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
for (int i = 0; i < numberOfCameras; i++)
{
Camera.GetCameraInfo(i, cameraInfo);
if (cameraInfo.Facing == CameraFacing.Back)
{
rearFacingCameraId = i;
}
}
if (rearFacingCameraId.HasValue)
{
camera = Camera.Open(rearFacingCameraId.Value);
if (cameraPreview != null)
{
cameraPreview.PreviewCamera = camera;
}
}
}
catch (CameraAccessException ex)
{
}
catch (NullPointerException)
{
}
catch (System.Exception ex)
{
}
}
示例2: 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);
}
}
示例3: TurnOff
/// <summary>
/// Turn the lamp off
/// </summary>
public void TurnOff()
{
if (camera == null)
camera = Camera.Open();
if (camera == null)
{
Debug.WriteLine("Camera failed to initialize");
return;
}
var p = camera.GetParameters();
var supportedFlashModes = p.SupportedFlashModes;
if (supportedFlashModes == null)
supportedFlashModes = new List<string>();
var flashMode = string.Empty;
if (supportedFlashModes.Contains(Android.Hardware.Camera.Parameters.FlashModeTorch))
flashMode = Android.Hardware.Camera.Parameters.FlashModeOff;
if (!string.IsNullOrEmpty(flashMode))
{
p.FlashMode = flashMode;
camera.SetParameters(p);
}
}
示例4: OnCreateView
public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
// Open an instance of the first camera and retrieve its info.
camera = GetCameraInstance (CAMERA_ID);
Camera.CameraInfo cameraInfo = null;
if (camera != null) {
// Get camera info only if the camera is available
cameraInfo = new Camera.CameraInfo ();
Camera.GetCameraInfo (CAMERA_ID, cameraInfo);
}
if (camera == null || cameraInfo == null) {
Toast.MakeText (Activity, "Camera is not available.", ToastLength.Short).Show ();
return inflater.Inflate (Resource.Layout.fragment_camera_unavailable, null);
}
View root = inflater.Inflate (Resource.Layout.fragment_camera, null);
// Get the rotation of the screen to adjust the preview image accordingly.
SurfaceOrientation displayRotation = Activity.WindowManager.DefaultDisplay.Rotation;
// Create the Preview view and set it as the content of this Activity.
cameraPreview = new CameraPreview (Activity, camera, cameraInfo, displayRotation);
var preview = root.FindViewById <FrameLayout> (Resource.Id.camera_preview);
preview.AddView (cameraPreview);
return root;
}
示例5: OnSurfaceTextureAvailable
public void OnSurfaceTextureAvailable (Android.Graphics.SurfaceTexture surface, int width, int height)
{
if (Camera.NumberOfCameras == 0) {
Toast.MakeText (this, Resource.String.no_camera, ToastLength.Long).Show ();
return;
}
_camera = Camera.Open();
if (_camera == null)
_camera = Camera.Open (0);
var previewSize = _camera.GetParameters ().PreviewSize;
_textureView.LayoutParameters =
new FrameLayout.LayoutParams (previewSize.Width, previewSize.Height, 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: OnCreate
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.ScannerView);
var frameLayout = (FrameLayout)FindViewById(Resource.Id.cameraPreview);
camera = GetCameraInstance();
if (camera == null)
{
Complete(new Intent());
return;
}
previewCb = new PreviewCallback();
previewCb.ScanComplete += PreviewCb_ScanComplete;
camPreview = new CameraPreview(this, camera, previewCb);
frameLayout.AddView(camPreview);
}
示例7: OnPause
public override void OnPause()
{
base.OnPause();
if (mCamera != null) {
mCamera.Release();
mCamera = null;
}
}
示例8: StartCamera
protected void StartCamera() {
if (_Camera == null) {
_Camera = Camera.Open();
_CameraSupportedFlashModes = _CameraSupportedFlashModes ?? _Camera.GetParameters().SupportedFlashModes;
if (_CameraSupportedFlashModes == null || !_CameraSupportedFlashModes.Contains(FlashlightOnMode) || !_CameraSupportedFlashModes.Contains(FlashlightOffMode)) {
StopCamera();
}
}
}
示例9: OnResume
protected override void OnResume ()
{
base.OnResume ();
// Open the default i.e. the first rear facing camera.
mCamera = Camera.Open ();
cameraCurrentlyLocked = defaultCameraId;
mPreview.PreviewCamera = mCamera;
}
示例10: GetCameraFlashMode
protected string GetCameraFlashMode(Camera.Parameters cameraParameters = null)
{
string mode = null;
if (_Camera != null) {
if (cameraParameters == null) {
cameraParameters = _Camera.GetParameters();
}
mode = cameraParameters.FlashMode;
}
return mode;
}
示例11: OnPause
protected override void OnPause ()
{
base.OnPause ();
// Because the Camera object is a shared resource, it's very
// important to release it when the activity is paused.
if (mCamera != null) {
mPreview.PreviewCamera = null;
mCamera.Release ();
mCamera = null;
}
}
示例12: CameraPreview
public CameraPreview(Context context, Camera.IPreviewCallback previewCallback, bool cameraPreviewCallbackWithBuffer)
: base(context)
{
_cameraPreviewCallbackWithBuffer = cameraPreviewCallbackWithBuffer;
// Install a SurfaceHolder.Callback so we get notified when the
// underlying surface is created and destroyed.
_surfaceHolder = Holder;
_surfaceHolder.AddCallback(this);
_cameraPreviewCallback = previewCallback;
}
示例13: CleanUpCamera
public void CleanUpCamera()
{
if (camera != null)
{
camera.StopPreview();
if (cameraPreview != null)
{
cameraPreview.PreviewCamera = null;
}
camera.Release();
camera = null;
}
}
示例14: SurfaceCreated
public void SurfaceCreated (ISurfaceHolder holder)
{
try
{
var version = Android.OS.Build.VERSION.SdkInt;
if (version >= BuildVersionCodes.Gingerbread)
{
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();
}
if (camera == null)
Android.Util.Log.Debug("ZXing.Net.Mobile", "Camera is null :(");
//camera = Android.Hardware.Camera.Open ();
camera.SetPreviewDisplay (holder);
//camera.SetPreviewCallback (this);
camera.SetOneShotPreviewCallback(this);
} catch (Exception ex) {
ShutdownCamera ();
// TODO: log or otherwise handle this exception
Console.WriteLine("Setup Error: " + ex);
//throw;
}
}
示例15: 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);
}
}