public void SetOrientation() { try { Android.Hardware.Camera camera = Methods.GetCamera(_cameraSource); switch (_windowManager.DefaultDisplay.Rotation) { case SurfaceOrientation.Rotation0: camera?.SetDisplayOrientation(90); break; case SurfaceOrientation.Rotation90: camera?.SetDisplayOrientation(0); break; case SurfaceOrientation.Rotation180: camera?.SetDisplayOrientation(270); break; case SurfaceOrientation.Rotation270: camera?.SetDisplayOrientation(180); break; } } catch (Exception ex) { Log.Error("BarcodeScanner.Droid", ex.Message); } }
public void SurfaceChanged(ISurfaceHolder holder, Format format, int width, int height) { var parameters = Preview.GetParameters(); parameters.SetPreviewSize(previewSize.Width, previewSize.Height); RequestLayout(); switch (windowManager.DefaultDisplay.Rotation) { case SurfaceOrientation.Rotation0: camera.SetDisplayOrientation(90); break; case SurfaceOrientation.Rotation90: camera.SetDisplayOrientation(0); break; case SurfaceOrientation.Rotation270: camera.SetDisplayOrientation(180); break; } Preview.SetParameters(parameters); Preview.StartPreview(); IsPreviewing = true; }
public void SurfaceChanged(ISurfaceHolder holder, [GeneratedEnum] Format format, int width, int height) { if (holder.Surface == null) { return; } try { _mCamera.StopPreview(); } catch (Exception e) { //TODO:KOA: remove Console! Console.WriteLine(Localization.Errors.ErrorCameraPreview + e.Message); } try { var p = _mCamera.GetParameters(); p.SetPreviewSize(_mPreviewSize.Width, _mPreviewSize.Height); if (p.SupportedFocusModes.Contains(Android.Hardware.Camera.Parameters.FocusModeContinuousVideo)) { p.FocusMode = Android.Hardware.Camera.Parameters.FocusModeContinuousVideo; _mCamera.SetParameters(p); } switch (Display.Rotation) { case SurfaceOrientation.Rotation0: _mCamera.SetDisplayOrientation(90); break; case SurfaceOrientation.Rotation90: break; case SurfaceOrientation.Rotation180: break; case SurfaceOrientation.Rotation270: _mCamera.SetDisplayOrientation(180); break; } p.SetPreviewSize(_mPreviewSize.Width, _mPreviewSize.Height); if (_mPictureSize != null) { p.SetPictureSize(_mPictureSize.Width, _mPictureSize.Height); } p.SetRotation(90); _mCamera.SetParameters(p); _mCamera.SetPreviewDisplay(holder); _mCamera.StartPreview(); } catch (Exception e) { //TODO:KOA: remove Console! Console.WriteLine(Localization.Errors.ErrorCameraPreview + e.Message); } }
protected override void OnLayout(bool changed, int l, int t, int r, int b) { base.OnLayout(changed, l, t, r, b); if (!changed) { return; } try { progressBar.Visibility = Android.Views.ViewStates.Invisible; var msw1 = MeasureSpec.MakeMeasureSpec(r, MeasureSpecMode.Exactly); var msh1 = MeasureSpec.MakeMeasureSpec(b, MeasureSpecMode.Exactly); mainLayout.Measure(msw1, msh1); mainLayout.Layout(l, t, r, b); if (mainLayout.Width < mainLayout.Height) { if (camera != null) { camera.SetDisplayOrientation(90); } int tmpPr = (mainLayout.Width / 100) * 10; capturePhotoButton.SetX(mainLayout.Width / 2 + tmpPr); capturePhotoButton.SetY(mainLayout.Height - 200); capturePhotoInspectionButton.SetY((mainLayout.Height / 2 + tmpPr) - 200); capturePhotoInspectionButton.SetX(mainLayout.Width - 200); scanPhotoButton.SetX(mainLayout.Width / 2 + tmpPr); scanPhotoButton.SetY(mainLayout.Height - 200); progressBar.SetX(mainLayout.Width / 2 + tmpPr); progressBar.SetY(mainLayout.Height - 200); } else { if (camera != null) { camera.SetDisplayOrientation(0); } int tmpPr = (mainLayout.Width / 100) * 10; capturePhotoButton.SetY(mainLayout.Height / 2 + tmpPr); capturePhotoButton.SetX(mainLayout.Width - 200); capturePhotoInspectionButton.SetY((mainLayout.Height / 2 + tmpPr) - 200); capturePhotoInspectionButton.SetX(mainLayout.Width - 200); scanPhotoButton.SetY(mainLayout.Height / 2 + tmpPr); scanPhotoButton.SetX(mainLayout.Width - 200); progressBar.SetY(mainLayout.Height / 2 + tmpPr); progressBar.SetX(mainLayout.Width - 200); } } catch (NullReferenceException) { } }
public Camera() : base(Forms.Context) { cam = Android.Hardware.Camera.Open(); #pragma warning restore 618 Log("cam Opened"); switch ( ((Android.Views.IWindowManager)Context.GetSystemService(Android.Content.Context.WindowService)) .DefaultDisplay.Rotation) { case Android.Views.SurfaceOrientation.Rotation0: cam.SetDisplayOrientation(90); break; case Android.Views.SurfaceOrientation.Rotation180: cam.SetDisplayOrientation(270); break; case Android.Views.SurfaceOrientation.Rotation270: cam.SetDisplayOrientation(180); break; case Android.Views.SurfaceOrientation.Rotation90: cam.SetDisplayOrientation(0); break; default: break; } try { cam.SetPreviewCallback(new Callback( (data, camera) => { var Prev = Drawable; using (var s = new System.IO.MemoryStream(data)) SetImageDrawable(new Android.Graphics.Drawables.BitmapDrawable(s)); Prev?.Dispose(); } )); Log("Preview set"); cam.StartPreview(); Log("Preview started"); } catch (Java.IO.IOException ex) { Log(ex); } }
public void SetCameraDisplayOrientation() { if (_camera == null) { return; } var windowManager = Application.Context.GetSystemService(Context.WindowService).JavaCast <IWindowManager>(); var rotation = windowManager.DefaultDisplay.Rotation; int degrees; switch (rotation) { case SurfaceOrientation.Rotation0: degrees = 90; break; case SurfaceOrientation.Rotation90: degrees = 0; break; case SurfaceOrientation.Rotation180: degrees = 270; break; case SurfaceOrientation.Rotation270: degrees = 180; break; default: degrees = 0; break; } _camera.SetDisplayOrientation(degrees); }
private void InitView(Android.Hardware.Camera camera) { this.camera = camera; camera.SetDisplayOrientation(90); Holder.AddCallback(this); Holder.SetType(SurfaceType.PushBuffers); }
public void OnSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { _textureView.LayoutParameters = new FrameLayout.LayoutParams(width, height); try { _camera.SetPreviewTexture(surface); _camera.SetDisplayOrientation(90); _camera.StartPreview(); } catch (Java.IO.IOException ex) { Console.WriteLine(ex.Message); } }
private void InitCamera() { //bool success = false; //success = OpenCamera(0); //Try the face camera //if (success == false) //{ // success = OpenCamera(1); //Try the rear camera //} //variable to get the number of cameras in the device int cameraCount = Android.Hardware.Camera.NumberOfCameras; Android.Hardware.Camera.CameraInfo cameraInfo = new Android.Hardware.Camera.CameraInfo(); for (int camIdx = 0; camIdx < cameraCount; camIdx++) { Android.Hardware.Camera.GetCameraInfo(camIdx, cameraInfo); if (cameraInfo.Facing == Android.Hardware.CameraFacing.Front) { camera = Android.Hardware.Camera.Open(camIdx); cameraId = camIdx; camera.SetDisplayOrientation(90); } } //var video = Activity.FindViewById<VideoView>(Resource.Id.videoView1); //camera.SetPreviewDisplay(video.Holder); camera.AddCallbackBuffer(ss); camera.SetPreviewCallbackWithBuffer(new mPreviewCallback()); camera.StartPreview(); }
public void SurfaceCreated(ISurfaceHolder holder) { //If authorisation not granted for camera if (ContextCompat.CheckSelfPermission(CurrentContext, Manifest.Permission.Camera) != Permission.Granted) { //ask for authorisation ActivityCompat.RequestPermissions(CurrentContext, new System.String[] { Manifest.Permission.Camera }, 50); } else { if (camera != null) { camera.Release(); camera = null; } camera = Android.Hardware.Camera.Open(); camera.SetDisplayOrientation(90); Parameters parameters = camera.GetParameters(); parameters.FocusMode = Parameters.FocusModeContinuousVideo; camera.SetParameters(parameters); camera.SetPreviewDisplay(holder); camera.StartPreview(); initRecorder(); camera.Unlock(); } prepareRecorder(); }
private void StartCamera() { if (!(Element as VideoCameraPage).IsPreviewing) { if (mainLayout.Width < mainLayout.Height) { camera.SetDisplayOrientation(90); } else { camera.SetDisplayOrientation(0); } camera.StartPreview(); (Element as VideoCameraPage).IsPreviewing = true; } }
public void SurfaceChanged(ISurfaceHolder holder, [GeneratedEnum] Format format, int width, int height) { if (surfaceHolder.Surface == null) { return; } try { cameraInstance.StopPreview(); cameraInstance.SetPreviewDisplay(surfaceHolder); Android.Hardware.Camera.Parameters parameters = cameraInstance.GetParameters(); Android.Hardware.Camera.Size optimalSize = CameraHelpers.GetOptimalPreviewSize(context, cameraInstance, width, height); parameters.SetPreviewSize(optimalSize.Width, optimalSize.Height); parameters.SetPictureSize(optimalSize.Width, optimalSize.Height); parameters.FocusMode = Android.Hardware.Camera.Parameters.FocusModeContinuousPicture; cameraInstance.SetParameters(parameters); cameraInstance.SetDisplayOrientation(CameraHelpers.GetCameraOrientation(context)); cameraInstance.StartPreview(); } catch (Exception e) { Log.Debug("Camera activity", "Error starting camera preview: " + e.Message); } }
private void SetCameraDisplayOrientation() { if (_camera == null) { return; } // определ¤ем насколько повернут экран от нормального положени¤ SurfaceOrientation rotation = _activity.WindowManager.DefaultDisplay.Rotation; int degrees = 0; switch (rotation) { case SurfaceOrientation.Rotation0: degrees = 0; break; case SurfaceOrientation.Rotation90: degrees = 90; break; case SurfaceOrientation.Rotation180: degrees = 180; break; case SurfaceOrientation.Rotation270: degrees = 270; break; } int result = 0; // получаем инфо по камере cameraId Android.Hardware.Camera.CameraInfo info = new Android.Hardware.Camera.CameraInfo(); Android.Hardware.Camera.GetCameraInfo(0, info); // задн¤¤ камера if (info.Facing == Android.Hardware.CameraFacing.Back) { result = ((360 - degrees) + info.Orientation); } else if (info.Facing == Android.Hardware.CameraFacing.Front) { // передн¤¤ камера result = ((360 - degrees) - info.Orientation); result += 360; } result = result % 360; try { _camera.SetDisplayOrientation(result); } catch (Java.Lang.Exception e) { e.PrintStackTrace(); } }
public CameraPreview(Context context, Android.Hardware.Camera camera) : base(context) { _camera = camera; _camera.SetDisplayOrientation(rotation); Holder.AddCallback(this); // deprecated but required on Android versions less than 3.0 Holder.SetType(SurfaceType.PushBuffers); }
private void InitCamera() { try { camera = Android.Hardware.Camera.Open(); camera.SetDisplayOrientation(90); camera.Unlock(); } catch { } }
public CameraPreview(Context context, Android.Hardware.Camera camera) : base(context) { _camera = camera; _camera.SetDisplayOrientation(0); //Surface holder callback is set so theat SurfaceChanged, Created, destroy... //Could be called from here. Holder.AddCallback(this); // deprecated but required on Android versions less than 3.0 Holder.SetType(SurfaceType.PushBuffers); }
public CameraPreview(Context context, Android.Hardware.Camera cameraa) : base(context) { camera = cameraa; camera.SetDisplayOrientation(90);// Вылетает на этой строчке !!! Если закоментировать - переходит к строке номер 68 и выдаёт такую же ошибку !!! //Surface holder callback is set so theat SurfaceChanged, Created, destroy... //Could be called from here. Holder.AddCallback(this); // deprecated but required on Android versions less than 3.0 Holder.SetType(SurfaceType.PushBuffers); }
private void OpenCamera() { if (CheckSelfPermission(Manifest.Permission.Camera) != Permission.Granted) { RequestCameraPermission(); return; } camera = Open(); Parameters parameters = camera.GetParameters(); parameters.PictureFormat = ImageFormatType.Jpeg; parameters.PreviewFormat = ImageFormatType.Nv21; if (parameters.SupportedFocusModes.Contains(Parameters.FocusModeContinuousVideo)) { parameters.FocusMode = Parameters.FocusModeContinuousVideo; } IList <Size> suportedPreviewSizes = parameters.SupportedPreviewSizes; int i = 0; for (i = 0; i < suportedPreviewSizes.Count; i++) { if (suportedPreviewSizes[i].Width < 1300) { break; } } parameters.SetPreviewSize(suportedPreviewSizes[i].Width, suportedPreviewSizes[i].Height); camera.SetParameters(parameters); camera.SetDisplayOrientation(90); camera.SetPreviewCallback(this); camera.SetPreviewDisplay(surface.Holder); camera.StartPreview(); //Get camera width previewWidth = parameters.PreviewSize.Width; //Get camera height previewHeight = parameters.PreviewSize.Height; //Resize SurfaceView Size float scaledHeight = previewWidth * 1.0f * surface.Width / previewHeight; float prevHeight = surface.Height; ViewGroup.LayoutParams lp = surface.LayoutParameters; lp.Width = surface.Width; lp.Height = (int)scaledHeight; surface.LayoutParameters = lp; surface.Top = (int)((prevHeight - scaledHeight) / 2); surface.DrawingCacheEnabled = true; handlerThread = new HandlerThread("background"); handlerThread.Start(); //backgroundHandler = new MyHandler(handlerThread.Looper); backgroundHandler = new MyHandler(Looper.MainLooper); }
public void SetOrientation() { Android.Hardware.Camera camera = Methods.GetCamera(_cameraSource); switch (_windowManager.DefaultDisplay.Rotation) { case SurfaceOrientation.Rotation0: camera?.SetDisplayOrientation(90); break; case SurfaceOrientation.Rotation90: camera?.SetDisplayOrientation(0); break; case SurfaceOrientation.Rotation180: camera?.SetDisplayOrientation(270); break; case SurfaceOrientation.Rotation270: camera?.SetDisplayOrientation(180); break; } }
public void SurfaceCreated(ISurfaceHolder holder) { // throw new NotImplementedException(); // open camera's parameters camera = Android.Hardware.Camera.Open(); camera.SetDisplayOrientation(90); Android.Hardware.Camera.Parameters p = camera.GetParameters(); p.PictureFormat = ImageFormatType.Jpeg; camera.SetParameters(p); camera.SetPreviewCallback(this); camera.SetPreviewDisplay(holder); camera.StartPreview(); }
public void OnSurfaceTextureUpdated(SurfaceTexture surface) { if (_camera != null) { try { var display = this.WindowManager.DefaultDisplay; if (display.Rotation == SurfaceOrientation.Rotation0) { _camera.SetDisplayOrientation(90); } else { _camera.SetDisplayOrientation(180); } _camera.StartPreview(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
// 画面の向きに合わせてSurfaceViewの向きを変更 public bool SetScreenOrientation() { var orientation = DetectScreenOrientation(); bool ReturnValue = false; if ((orientation == 0) || (orientation == 180)) { m_Camera.SetDisplayOrientation(90); ReturnValue = false; } else if (orientation == 90) { m_Camera.SetDisplayOrientation(0); ReturnValue = true; } else if (orientation == 270) { m_Camera.SetDisplayOrientation(180); ReturnValue = true; } return(ReturnValue); }
public void OnSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { _camera = Android.Hardware.Camera.Open(); try { _camera.SetPreviewTexture(surface); _camera.SetDisplayOrientation(90); // возможно тут решение проблемы искажения при переворачивании _camera.StartPreview(); } catch (Java.IO.IOException ex) { Console.WriteLine("OnSurfaceTextureAvailable - " + ex.Message); } } // end of OnSurfaceTextureAvailable
public void OnSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { _camera = Android.Hardware.Camera.Open(); try { _camera.SetPreviewTexture(surface); _camera.SetDisplayOrientation(90); _camera.StartPreview(); } catch (Java.IO.IOException ex) { Console.WriteLine(ex.Message); } }
//Camera stuff public void OnSurfaceTextureAvailable(Android.Graphics.SurfaceTexture surface, int w, int h) { if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.Camera) == (int)Permission.Granted) { camera = Android.Hardware.Camera.Open(); cameraSurfaceView.LayoutParameters = new RelativeLayout.LayoutParams(w, h); try { camera.SetPreviewTexture(surface); camera.SetDisplayOrientation(90); camera.StartPreview(); } catch (Java.IO.IOException ex) { Console.WriteLine(ex.Message); } } }
protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Page> e) { base.OnElementChanged(e); if (camera != null) { camera.Release(); camera = null; } camera = Android.Hardware.Camera.Open(); camera.SetDisplayOrientation(90); Parameters parameters = camera.GetParameters(); parameters.FocusMode = Parameters.FocusModeContinuousVideo; camera.SetParameters(parameters); SetupUserInterface(); SetupEventHandlers(); AddView(view); }
public void SurfaceChanged(ISurfaceHolder holder, 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.SetDisplayOrientation(90); camera.SetParameters(parameters); int dataBufferSize = (int)(optimalSize.Width * optimalSize.Height * (ImageFormat.GetBitsPerPixel(camera.GetParameters().PreviewFormat) / 8.0)); _reader = new QRCodeReader(); camera.StartPreview(); }
public void OnSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { try { _camera = Android.Hardware.Camera.Open(GetFrontCameraId()); _camera.SetDisplayOrientation(90); var pictureSize = _camera.GetParameters().PictureSize; var previewSize = _camera.GetParameters().PreviewSize; // Need to flip around width and height because of the rotation textureView.LayoutParameters = new RelativeLayout.LayoutParams(pictureSize.Height, pictureSize.Width); var aspectRatio = ((double)pictureSize.Height) / ((double)pictureSize.Width); var lp = this.gameoverOverlayLayer.LayoutParameters; lp.Height = (int)(Resources.DisplayMetrics.HeightPixels * 0.6); lp.Width = (int)(lp.Height * aspectRatio); this.gameoverOverlayLayer.LayoutParameters = lp; _camera.SetPreviewTexture(surface); _camera.StartPreview(); } catch (Java.IO.IOException ex) { System.Console.WriteLine(ex.Message); } }
public void SurfaceCreated(ISurfaceHolder holder) { try { // if only front camera, get it camera = Camera.Open(0); Camera.Parameters p = camera.GetParameters(); p.PictureFormat = Android.Graphics.ImageFormatType.Jpeg; camera.EnableShutterSound(true); // fix camera rotation camera.SetDisplayOrientation(0); camera.SetParameters(p); camera.SetPreviewCallback(this); camera.Lock(); camera.SetPreviewDisplay(holder); camera.StartPreview(); } catch (Java.IO.IOException e) { } }
private void StartCamera() { camera.SetDisplayOrientation(90); 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. //Android.Hardware.Camera.Parameters parameters = PreviewCamera.GetParameters(); //parameters.SetPreviewSize(mPreviewSize.Width, mPreviewSize.Height); //RequestLayout(); //PreviewCamera.SetParameters(parameters); //PreviewCamera.StartPreview(); //if (mSupportedPreviewSizes != null) //{ // mPreviewSize = _Context.GetOptimalPreviewSize(mSupportedPreviewSizes); //} if (_camera == null) { return; } if (_Context.previewing) { //_camera.StopPreview(); //_Context.previewing = false; if (this.Resources.Configuration.Orientation != Android.Content.Res.Orientation.Landscape) { _camera.SetDisplayOrientation(90); //Android.Hardware.Camera.Size cameraSize = _camera.GetParameters().PictureSize; //int wr = relativeLayout.Width; //int hr = relativeLayout.Height; //float ratio = relativeLayout.Width * 1f / cameraSize.Height; //w = cameraSize.Width * ratio; //h = cameraSize.Height * ratio; //RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams((int)h, (int)w); //cameraSurfaceView.LayoutParameters = (lp); } else { _camera.SetDisplayOrientation(0); //Android.Hardware.Camera.Size cameraSize = camera.GetParameters().PictureSize; //float ratio = relativeLayout.Height * 1f / cameraSize.Height; //w = cameraSize.Width * ratio; //h = cameraSize.Height * ratio; //RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams((int)w, (int)h); //cameraSurfaceView.LayoutParameters = (lp); } return; } try { //float w = 0; //float h = 0; if (this.Resources.Configuration.Orientation != Android.Content.Res.Orientation.Landscape) { _camera.SetDisplayOrientation(90); //Android.Hardware.Camera.Size cameraSize = _camera.GetParameters().PictureSize; //int wr = relativeLayout.Width; //int hr = relativeLayout.Height; //float ratio = relativeLayout.Width * 1f / cameraSize.Height; //w = cameraSize.Width * ratio; //h = cameraSize.Height * ratio; //RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams((int)h, (int)w); //cameraSurfaceView.LayoutParameters = (lp); } else { _camera.SetDisplayOrientation(0); //Android.Hardware.Camera.Size cameraSize = camera.GetParameters().PictureSize; //float ratio = relativeLayout.Height * 1f / cameraSize.Height; //w = cameraSize.Width * ratio; //h = cameraSize.Height * ratio; //RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams((int)w, (int)h); //cameraSurfaceView.LayoutParameters = (lp); } //camera.SetPreviewDisplay(cameraSurfaceHolder); //camera.StartPreview(); Android.Hardware.Camera.Parameters parameters = PreviewCamera.GetParameters(); parameters.SetPreviewSize(mPreviewSize.Width, mPreviewSize.Height); Console.WriteLine("Param mPreviewSize.Width:" + mPreviewSize.Width + " mPreviewSize.height:" + mPreviewSize.Height); RequestLayout(); parameters.SetPictureSize(mPreviewSize.Width, mPreviewSize.Height); parameters.JpegQuality = (100); parameters.PictureFormat = (ImageFormat.Jpeg); PreviewCamera.SetParameters(parameters); PreviewCamera.GetParameters().FocusMode = Android.Hardware.Camera.Parameters.FocusModeAuto; if (PreviewCamera.GetParameters().IsZoomSupported) { PreviewCamera.GetParameters().Zoom = (0); } PreviewCamera.StartPreview(); _Context.previewing = true; } catch (System.Exception e) { System.Console.WriteLine("SurfaceChanged:" + e.ToString()); } }