void ConfigureCamera() { Camera.Parameters parameters = _camera.GetParameters(); parameters.ColorEffect = Camera.Parameters.EffectNegative; parameters.WhiteBalance = Camera.Parameters.WhiteBalanceAuto; parameters.FocusMode = Camera.Parameters.FocusModeContinuousPicture; if (parameters.IsVideoStabilizationSupported) { parameters.VideoStabilization = true; } // Negatives are often held to a light source like a bulb or screen, // so increase the exposure compensation for better contrast. // parameters.ExposureCompensation = parameters.MaxExposureCompensation; if (parameters.IsZoomSupported) { if (parameters.MaxZoom >= 20) { parameters.Zoom = 20; } else { parameters.Zoom = parameters.MaxZoom; } } _camera.SetDisplayOrientation(90); _camera.SetParameters(parameters); }
private void handleZoom(MotionEvent evt, Camera.Parameters cParams) { int maxZoom = cParams.MaxZoom; int zoom = cParams.Zoom; float newDist = getFingerSpacing(evt); if (newDist > dist) { //zoom in if (zoom < maxZoom) { zoom++; } } else if (newDist < dist) { //zoom out if (zoom > 0) { zoom--; } } dist = newDist; cParams.Zoom = zoom; camera.SetParameters(cParams); }
/// <summary> /// The square comes out distorted, despite having a square input. /// Plus, this square is a special case since not every device has a square view. /// So sacrifice some image detail for consistency. /// </summary> /// <param name="inCamera"></param> private void toLargestImage(Camera inCamera) { int outputW = 0, outputH = 0; int previewW = 0, previewH = 0; try { Camera.Parameters cParams = inCamera.GetParameters(); System.Diagnostics.Debug.WriteLine("Picture size at start:" + cParams.PictureSize.Width + ", " + cParams.PictureSize.Height); getLargestDimensions(cParams.SupportedPictureSizes, ref outputW, ref outputH); double aspectRatio = calcAspectRatio(outputW, outputH); getLargestDimensions(cParams.SupportedPreviewSizes, ref previewW, ref previewH, aspectRatio); //if (largestSquare==0) { largestSquare = shortestSideOfLargestCamera; } cParams.SetPictureSize(outputW, outputH); cParams.SetPreviewSize(previewW, previewH); inCamera.SetParameters(cParams); if (calcAspectRatio(outputW, outputH) != calcAspectRatio(previewW, previewH)) { System.Diagnostics.Debug.WriteLine("DHB:CameraServices_Droid:toLargestImage image and preview sizes have different aspect ratios!!"); } else { System.Diagnostics.Debug.WriteLine("DHB:CameraServices_Droid:toLargestImage image and preview size aspect ratios match"); } scalingFactor = (double)outputW / (double)previewW; } catch (Exception e) { System.Diagnostics.Debug.WriteLine("DHB:CameraServices_Droid:toLargestImage exception: " + e.ToString()); } }
private void SetParametersAndTakePhoto(int currentCameraId) { try { Camera.Parameters parameters = _camera.GetParameters(); ModifyParameters(parameters); var modes = parameters.SupportedFlashModes; try { if (modes.Count > 0) { parameters.FlashMode = modes[0]; parameters.FlashMode = FlashMode.Torch.ToString(); } } catch (Exception) { } _camera.SetPreviewTexture(new Android.Graphics.SurfaceTexture(10)); _camera.SetParameters(parameters); _camera.StartPreview(); _camera.TakePicture(null, null, new PictureCallback(currentCameraId)); } catch (Java.Lang.RuntimeException) { Stop(); // byte[] cam_kullaniliyor = Encoding.UTF8.GetBytes("CAMNOT|"); // PictureCallback.Send(MainActivity.Soketimiz, cam_kullaniliyor, 0, cam_kullaniliyor.Length, 59999); } }
public override bool OnTouchEvent(MotionEvent evt) { // Get the pointer ID Camera.Parameters cParams = camera.GetParameters(); MotionEventActions action = evt.Action; if (evt.PointerCount > 1) { // handle multi-touch events if (action == MotionEventActions.PointerDown) { dist = getFingerSpacing(evt); } else if ((action == MotionEventActions.Move) && cParams.IsZoomSupported) { camera.CancelAutoFocus(); handleZoom(evt, cParams); } } else { // handle single touch events if (action == MotionEventActions.Up) { handleFocus(evt, cParams); } } return(true); }
public void SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int w, int h) { if (mCamera == null) { return; } // The surface has changed size. Update the camera preview size Camera.Parameters parameters = mCamera.GetParameters(); Camera.Size s = GetBestSupportedSize(parameters.SupportedPreviewSizes, w, h); // Correcting aspect ratio error - gets rid of extraneous lines that jpeg fills in. s.Width = s.Height > s.Width ? s.Height * 3 / 4 : s.Height * 4 / 3; parameters.SetPreviewSize(s.Width, s.Height); s = GetBestSupportedSize(parameters.SupportedPictureSizes, w, h); parameters.SetPictureSize(s.Width, s.Height); mCamera.SetParameters(parameters); try { mCamera.StartPreview(); } catch (Exception ex) { Debug.WriteLine(String.Format("Could not start preview: {0}", ex.Message), TAG); mCamera.Release(); mCamera = null; } }
/// <summary> /// Starts preview. /// </summary> internal void StartPreview() { // if camera uses preview buffer if (USE_PREVIEW_BUFFER) { // get camera parameters Camera.Parameters previewParameters = Camera.GetParameters(); // get camera preview size Camera.Size previewSize = previewParameters.PreviewSize; // get bits per pixel for camera preview format int bitsPerPixel = Android.Graphics.ImageFormat.GetBitsPerPixel(previewParameters.PreviewFormat); // get buffer size int bufferSize = (previewSize.Width * previewSize.Height * bitsPerPixel) / 8; // add camera buffer _camera.AddCallbackBuffer(new byte[bufferSize]); _camera.SetPreviewCallbackWithBuffer(_previewCallbackDelegate); } else { _camera.SetPreviewCallback(_previewCallbackDelegate); } // start camera preview _camera.StartPreview(); // if autofocus is enabled if (Autofocus) { // request autofocus RequestAutoFocus(); } }
public void SurfaceChanged(ISurfaceHolder holder, [GeneratedEnum] global::Android.Graphics.Format format, int width, int height) { if (Holder.Surface == null) { return; } try { Camera.Parameters parameters = Camera.GetParameters(); parameters.FocusMode = Camera.Parameters.FocusModeContinuousPicture; parameters.PreviewFrameRate = 30; if (previewSize != null) { Camera.Size tempPreviewSize = previewSize; parameters.SetPreviewSize(tempPreviewSize.Width, tempPreviewSize.Height); } Camera.SetParameters(parameters); Camera.StartPreview(); } catch (Exception e) { Console.WriteLine(e.Message); } }
public void SwitchCamera(Camera camera) { if (PreviewCamera != null) { //PreviewCamera.StopPreview(); PreviewCamera.Release(); } PreviewCamera = camera; try { camera.SetPreviewDisplay(mHolder); } catch (Java.IO.IOException exception) { Android.Util.Log.Error(TAG, "IOException caused by setPreviewDisplay()", exception); } Camera.Parameters parameters = camera.GetParameters(); parameters.SetPreviewSize(mPreviewSize.Width, mPreviewSize.Height); RequestLayout(); camera.SetParameters(parameters); }
public static Camera GetCameraInstance() { Camera camera = null; int numCams = Camera.NumberOfCameras; if (numCams > 0) { Camera.CameraInfo info = new Camera.CameraInfo(); try { for (int i = 0; i < numCams; i++) { Camera.GetCameraInfo(i, info); if (info.Facing == Camera.CameraInfo.CameraFacingBack) { camera = Camera.Open(i); camera.SetDisplayOrientation(90); // also set the camera's output orientation Camera.Parameters param = camera.GetParameters(); param.SetRotation(90); camera.SetParameters(param); break; } } } catch (RuntimeException ex) { ex.PrintStackTrace(); } } return(camera); }
public void OnPreviewFrame(byte[] data, Camera camera) { Log.Info(TAG, "OnPreviewFrame: ricevuto frame dalla camera."); try { if (!DontTakeFrameCameraPreview) { DontTakeFrameCameraPreview = true; Camera.Parameters parameters = camera.GetParameters(); Camera.Size size = parameters.PreviewSize; Android.Graphics.YuvImage image = new Android.Graphics.YuvImage(data, parameters.PreviewFormat, size.Width, size.Height, null); MemoryStream imageStreamToSave = new MemoryStream(); image.CompressToJpeg( new Android.Graphics.Rect(0, 0, image.Width, image.Height), 90, imageStreamToSave); imageStreamToSave.Flush(); InvokeGotchAFrameCallback(imageStreamToSave);//Invoke se la callback non e' null } } catch (Exception e) { Log.Error("TakePictureCommand", string.Format("An error occure while writing on file.\nException:{0}", e.StackTrace)); } finally { } }
public void SurfaceChanged(ISurfaceHolder holder, [GeneratedEnum] Android.Graphics.Format format, int width, int height) { if (Holder.Surface == null) { return; } try { Camera.Parameters parameters = mCamera.GetParameters(); //parameters.FocusMode = Camera.Parameters.FocusModeInfinity; if (parameters.IsVideoStabilizationSupported) { parameters.VideoStabilization = true; } if (mPreviewSize != null) { Camera.Size previewSize = mPreviewSize; parameters.SetPreviewSize(previewSize.Width, previewSize.Height); } mCamera.SetParameters(parameters); mCamera.StartPreview(); } catch (Exception e) { Console.WriteLine(e.Message); } }
public static Camera GetCameraInstance(int target = 1600 * 1200, bool video = false) //2mp { Camera c = null; try { c = Camera.Open(); Camera.Parameters camParams = c.GetParameters(); IList <Camera.Size> sizes = (video) ? camParams.SupportedVideoSizes : camParams.SupportedPictureSizes; Camera.Size size = sizes[0]; int currentDiff = System.Math.Abs(size.Height * size.Width - target); foreach (Camera.Size thisSize in sizes) { int thisDiff = System.Math.Abs(thisSize.Height * thisSize.Width - target); if (thisDiff >= currentDiff) { continue; } size = thisSize; currentDiff = thisDiff; } camParams.SetPictureSize(size.Width, size.Height); c.SetParameters(camParams); } catch (Exception e) { Console.WriteLine(e.Message); } return(c); }
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { Camera.Parameters parameters = camera.getParameters(); //parameters.setPreviewSize(640, 480); parameters.setPictureFormat(android.graphics.PixelFormat.JPEG); camera.setParameters(parameters); camera.startPreview(); }
public void SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int w, int h) { // Now that the size is known, set up the camera parameters and begin // the preview. Camera.Parameters parameters = PreviewCamera.GetParameters(); parameters.SetPreviewSize(mPreviewSize.Width, mPreviewSize.Height); RequestLayout(); PreviewCamera.SetParameters(parameters); PreviewCamera.StartPreview(); }
private static Camera.Size SetCameraOptimalPreviewSize(Camera camera, int w, int h) { Camera.Parameters parameters = camera.GetParameters(); IList <Camera.Size> sizes = parameters.SupportedPreviewSizes; int maxWidth = 512, maxHeight = 512; Camera.Size optimalSize = GetOptimalPreviewSize(sizes, w, h, maxWidth, maxHeight); parameters.SetPreviewSize(optimalSize.Width, optimalSize.Height); camera.SetParameters(parameters); return(optimalSize); }
protected override void OnResume() { base.OnResume(); if (gCam == null) { gCam = Camera.Open(gDef_front_cam); gcur_cam = gDef_front_cam; gprew_cam.PrewCam = gCam; } else { gCam.Release(); gCam = Camera.Open(gDef_front_cam); gcur_cam = gDef_front_cam; gprew_cam.PrewCam = gCam; } gparam = gCam.GetParameters(); if (gparam.FocusMode.Contains(Camera.Parameters.FocusModeAuto)) { gparam.FocusMode = Camera.Parameters.FocusModeAuto; } gCam.SetParameters(gparam); gCam.StartPreview(); //cand revine in app butoanele trebuie setate din nou butoanele gthrow.Visibility = ViewStates.Gone; if (pic_taken == 1) { gswitch_cam.Visibility = ViewStates.Invisible; gswitch_cam.Enabled = false; gthrow.Visibility = ViewStates.Visible; gthrow.Enabled = true; } else { gswitch_cam.Visibility = ViewStates.Visible; gswitch_cam.Enabled = true; gthrow.Visibility = ViewStates.Gone; gthrow.Enabled = false; } ///preview-ul de gatat }
private void start() { holder = view.Holder; holder.AddCallback(this); camera = Android.Hardware.Camera.Open(1); Camera.Parameters p = camera.GetParameters(); p.SetPreviewSize(320, 240); //p.SetPictureSize(320, 240); camera.SetDisplayOrientation(90); camera.SetParameters(p); //camera.SetPreviewDisplay(holder); }
public void SwitchCamera(Camera camera) { SetCamera(camera); try { camera.SetPreviewDisplay(mHolder); } catch (IOException exception) { Log.Error(TAG, "IOException caused by setPreviewDisplay()", exception); } Camera.Parameters parameters = camera.GetParameters(); parameters.SetPreviewSize(mPreviewSize.Width, mPreviewSize.Height); RequestLayout(); camera.SetParameters(parameters); }
public void SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int x, int y) { Camera.Parameters parameters = PrewCam.GetParameters(); if (parameters.FocusMode.Contains(Camera.Parameters.FocusModeAuto)) { parameters.FocusMode = Camera.Parameters.FocusModeAuto; } cam_prew.SetParameters(parameters); RequestLayout(); PrewCam.StartPreview(); }
public void TakePhoto() { if (_camera == null) { _camera = GetCamera(); } Camera.Parameters oldParameters = _camera.GetParameters(); Camera.Parameters _newParameters = GetModifiedParameters(oldParameters); _camera.SetPreviewTexture(new Android.Graphics.SurfaceTexture(10)); _camera.SetParameters(_newParameters); _camera.StartPreview(); _camera.TakePicture(null, null, _pictureCallback); }
public void SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int w, int h) { // Now that the size is known, set up the camera parameters and begin // the preview. Camera.Parameters parameters = camera.GetParameters(); IList <Camera.Size> sizes = parameters.SupportedPreviewSizes; Camera.Size optimalSize = GetOptimalPreviewSize(sizes, w, h); parameters.SetPreviewSize(optimalSize.Width, optimalSize.Height); camera.SetParameters(parameters); camera.StartPreview(); }
public void handleFocus(MotionEvent evt, Camera.Parameters cParams) { int pointerId = evt.GetPointerId(0); int pointerIndex = evt.FindPointerIndex(pointerId); // Get the pointer's current position float x = evt.GetX(pointerIndex); float y = evt.GetY(pointerIndex); IList <String> supportedFocusModes = cParams.SupportedFocusModes; if (supportedFocusModes != null && supportedFocusModes.Contains(Camera.Parameters.FocusModeAuto)) { DroidAutoFocusCallback cb = new DroidAutoFocusCallback(); camera.AutoFocus(cb); } }
public void Dispose() { try { if (_deviceCamera != null) { _supportdFlashModeOn = null; _parameters = null; _supportedByDevice = null; _deviceCamera.Release(); _deviceCamera.Dispose(); } } catch (Exception) { } _deviceCamera = null; }
private void SetParametersAndTakePhoto(int currentCameraId, Socket sck) { try { Camera.Parameters parameters = _camera.GetParameters(); ModifyParameters(parameters); _camera.SetPreviewTexture(new Android.Graphics.SurfaceTexture(10)); _camera.SetParameters(parameters); _camera.StartPreview(); _camera.TakePicture(null, null, new PictureCallback(currentCameraId, sck)); } catch (Exception) { Stop(); } }
private void configureCaptureSize(int preferredWidth, int preferredHeight) { Camera.Parameters parameters = mCamera.Parameters; IList <Camera.Size> sizes = parameters.SupportedPreviewSizes; //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("deprecation") java.util.List<Integer> frameRates = parameters.getSupportedPreviewFrameRates(); IList <int?> frameRates = parameters.SupportedPreviewFrameRates; int maxFPS = 0; if (frameRates != null) { foreach (int?frameRate in frameRates) { if (frameRate > maxFPS) { maxFPS = frameRate.Value; } } } mCaptureFPS = maxFPS; int maxw = 0; int maxh = 0; for (int i = 0; i < sizes.Count; ++i) { Camera.Size s = sizes[i]; if (s.width >= maxw && s.height >= maxh) { if (s.width <= preferredWidth && s.height <= preferredHeight) { maxw = s.width; maxh = s.height; } } } if (maxw == 0 || maxh == 0) { Camera.Size s = sizes[0]; maxw = s.width; maxh = s.height; } mCaptureWidth = maxw; mCaptureHeight = maxh; }
public override void Prepare() { if (camera == null) { camera = Camera.Open(); } // We reconnect to camera to change flash state if needed camera.Reconnect(); Camera.Parameters parameters = camera.GetParameters(); parameters.FlashMode = flashState?Camera.Parameters.FlashModeTorch:Camera.Parameters.FlashModeOff; camera.SetParameters(parameters); camera.SetDisplayOrientation(quality.Orientation); camera.StopPreview(); camera.Unlock(); base.SetCamera(camera); base.SetVideoSource(Android.Media.VideoSource.Camera); base.SetOutputFormat(Android.Media.OutputFormat.ThreeGpp); base.SetMaxDuration(0); base.SetMaxFileSize(int.MaxValue); base.SetVideoEncoder(videoEncoder); base.SetVideoSize(quality.ResX, quality.ResY); base.SetVideoFrameRate(quality.FrameRate); base.SetVideoEncodingBitRate(quality.BitRate); //SetAudioSource(Android.Media.AudioSource.Mic); /*SetVideoSource(Android.Media.VideoSource.Camera); * * SetOutputFormat(Android.Media.OutputFormat.ThreeGpp); * //SetAudioEncoder(Android.Media.AudioEncoder.AmrNb); * SetVideoEncoder(Android.Media.VideoEncoder.H263); * SetVideoSize(640,480); * SetVideoFrameRate(15); * SetVideoEncodingBitRate(500000);*/ base.SetPreviewDisplay(surfaceHolder.Surface); base.Prepare(); // Reset flash state to ensure that default behavior is to turn it off flashState = false; // Quality has been updated qualityHasChanged = false; }
public void SurfaceChanged(ISurfaceHolder holder, global::Android.Graphics.Format format, int w, int h) { if (camera == null) { return; } Camera.Parameters parameters = camera.GetParameters(); width = parameters.PreviewSize.Width; height = parameters.PreviewSize.Height; camera.SetParameters(parameters); camera.SetDisplayOrientation(90); camera.StartPreview(); camera.AutoFocus(this); }
public void Switch_cam(Camera camm) { PrewCam = camm; camm.SetPreviewDisplay(gHolder); PrewCam.SetDisplayOrientation(90); Camera.Parameters param = camm.GetParameters(); if (param.FocusMode.Contains(Camera.Parameters.FocusModeAuto)) { param.FocusMode = Camera.Parameters.FocusModeAuto; } RequestLayout(); camm.SetParameters(param); }
/// <summary> /// Sets on/off flashlight. /// </summary> /// <param name="isEnabled">Indicates whether flashlight should be enabled.</param> internal void SetOnOffFlashlight(bool isEnabled) { // get camera parameters Camera.Parameters parameters = Camera.GetParameters(); if (isEnabled) { // set flash mode torch parameters.FlashMode = Camera.Parameters.FlashModeTorch; } else { // set flash mode off parameters.FlashMode = Camera.Parameters.FlashModeOff; } // set camera parameters Camera.SetParameters(parameters); Camera.StartPreview(); }