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; } }
private static PixelFormat GetPixelFormat(Android.Graphics.Format androidPixelFormat) { switch (androidPixelFormat) { case Android.Graphics.Format.A8: return(PixelFormat.PAlpha); case Android.Graphics.Format.Rgb565: return(PixelFormat.Format16bppRgb565); case Android.Graphics.Format.Rgb888: return(PixelFormat.Format24bppRgb); case Android.Graphics.Format.Rgba5551: return(PixelFormat.Format16bppArgb1555); case Android.Graphics.Format.Rgba8888: return(PixelFormat.Format32bppPArgb); default: throw new ArgumentOutOfRangeException( "androidPixelFormat", androidPixelFormat, "Unsupported Android pixel format."); } }
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 void SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int width, int height) { // If your preview can change or rotate, take care of those events here. // Make sure to stop the preview before resizing or reformatting it. if (Holder.Surface == null) { // preview surface does not exist return; } // stop preview before making changes try { camera.StopPreview(); } catch (Exception e) { // ignore: tried to stop a non-existent preview } // set preview size and make any resize, rotate or // reformatting changes here // start preview with new settings try { camera.SetPreviewDisplay(Holder); camera.StartPreview(); } catch (Exception e) { Android.Util.Log.Debug("CameraView", e.ToString()); } }
public void SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int w, int h) { // If your preview can change or rotate, take care of those events here. // Make sure to stop the preview before resizing or reformatting it. if (holder.Surface == null) { // preview surface does not exist CommonSampleLibrary.Log.Debug(TAG, "Preview surface does not exist"); return; } // stop preview before making changes try { camera.StopPreview(); CommonSampleLibrary.Log.Debug(TAG, "Preview stopped."); } catch (Exception e) { // ignore: tried to stop a non-existent preview CommonSampleLibrary.Log.Debug(TAG, "Error starting camera preview: " + e.Message); } int orientation = CalculatePreviewOrientation(cameraInfo, displayOrientation); camera.SetDisplayOrientation(orientation); try { camera.SetPreviewDisplay(holder); camera.StartPreview(); CommonSampleLibrary.Log.Debug(TAG, "Camera preview started."); } catch (Exception e) { CommonSampleLibrary.Log.Debug(TAG, "Error starting camera preview: " + e.Message); } }
public void SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int w, int h) { if (_surfaceHolder != holder) { _surfaceHolder = holder; _surfaceHolder.AddCallback(this); } // Now that the size is known, set up the camera parameters and begin // the preview. Camera.Size optimalSize = SetCameraOptimalPreviewSize(_camera, w, h); //set for protrait mode //camera.SetDisplayOrientation(90); if (_cameraPreviewCallback != null) { if (_cameraPreviewCallbackWithBuffer) { int bufferSize = optimalSize.Width * (optimalSize.Height >> 1) * 3; _camera.SetPreviewCallbackWithBuffer(_cameraPreviewCallback); for (int i = 0; i < 1; ++i) { _camera.AddCallbackBuffer(new byte[bufferSize]); } } else { _camera.SetPreviewCallback(_cameraPreviewCallback); } } _camera.StartPreview(); Layout(0, 0, optimalSize.Width, optimalSize.Height); }
void ISurfaceHolderCallback.SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int width, int height) { if ((int)Android.OS.Build.VERSION.SdkInt >= 19) { if (!_isSurfaceChanged) { _isSurfaceChanged = true; _prevSurfaceWidth = width; _prevSurfaceHeight = height; } else { // Forcing reinitialization of the view if SurfaceChanged() is called more than once to fix shifted drawing on KitKat. // See https://github.com/mono/MonoGame/issues/2492. if (!ScreenReceiver.ScreenLocked && Game.Instance.Platform.IsActive && (_prevSurfaceWidth != width || _prevSurfaceHeight != height)) { _prevSurfaceWidth = width; _prevSurfaceHeight = height; base.SurfaceDestroyed(holder); base.SurfaceCreated(holder); } } } SurfaceChanged(holder, format, width, height); Android.Util.Log.Debug("MonoGame", "MonoGameAndroidGameView.SurfaceChanged: format = " + format + ", width = " + width + ", height = " + height); if (_game.GraphicsDevice != null) { _game.graphicsDeviceManager.ResetClientBounds(); } }
public void SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int width, int height) { var parameters = Preview.GetParameters(); //プレビューサイズ設定 if (supportedPreviewSizes != null) { previewSize = GetOptimalPreviewSize(supportedPreviewSizes, surfaceView.Width, surfaceView.Height); } parameters.SetPreviewSize(previewSize.Width, previewSize.Height); //フレームレート設定 //parameters.SetPreviewFpsRange(10000, 24000); 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, Android.Graphics.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, Android.Graphics.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; } float previewSizeRatio = 0; if (windowManager.DefaultDisplay.Rotation == SurfaceOrientation.Rotation0) // 90 { previewSizeRatio = (float)previewSize.Height / (float)previewSize.Width; } else { previewSizeRatio = (float)previewSize.Width / (float)previewSize.Height; } float surfaceViewRatio = (float)surfaceView.Width / (float)surfaceView.Height; float scaleX; float scaleY; if (previewSizeRatio < surfaceViewRatio) { scaleX = 1; scaleY = surfaceViewRatio / previewSizeRatio; } else { scaleX = previewSizeRatio / surfaceViewRatio; scaleY = 1; } surfaceView.ScaleX = scaleX; surfaceView.ScaleY = scaleY; //surfaceView.TranslationX = dx; //surfaceView.TranslationY = dy; Preview.SetParameters(parameters); Preview.StartPreview(); IsPreviewing = true; }
public void SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int width, int height) { if (Preview == null) { Initialize(); } }
public void SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int width, int height) { if (camera_ != null) { camera_.StopPreview(); camera_.SetPreviewDisplay(holder); camera_.StartPreview(); } }
void ISurfaceHolderCallback.SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int width, int height) { lock (androidViewLock) { SurfaceChanged(holder, format, width, height); ViewSize = new CCSizeI(width, height); viewportDirty = true; } }
public void SurfaceChanged(ISurfaceHolder holder, [GeneratedEnum] Android.Graphics.Format format, int width, int height) { if (mHolder.Surface == null) { return; } mCamera.StopPreview(); mCamera.SetPreviewDisplay(mHolder); mCamera.StartPreview(); }
void ISurfaceHolderCallback.SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int width, int height) { base.SurfaceChanged(holder, format, width, height); Android.Util.Log.Debug("MonoGame", "AndroidGameWindow.SurfaceChanged: format = " + format + ", width = " + width + ", height = " + height); if (_game.GraphicsDevice != null) { _game.graphicsDeviceManager.ResetClientBounds(); } }
void ISurfaceHolderCallback.SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int width, int height) { if ((int)Android.OS.Build.VERSION.SdkInt >= 19) { if (!_isSurfaceChanged) { _isSurfaceChanged = true; _prevSurfaceWidth = width; _prevSurfaceHeight = height; } else { // Forcing reinitialization of the view if SurfaceChanged() is called more than once to fix shifted drawing on KitKat. // See https://github.com/mono/MonoGame/issues/2492. if (!ScreenReceiver.ScreenLocked && Game.Instance.Platform.IsActive && (_prevSurfaceWidth != width || _prevSurfaceHeight != height)) { _prevSurfaceWidth = width; _prevSurfaceHeight = height; base.SurfaceDestroyed(holder); base.SurfaceCreated(holder); } } } // When the game is resumed from a portrait orientation it may receive a portrait surface at first. // If the game does not support portrait we should ignore it because we will receive the landscape surface a moment later. if (width < height && (_game.graphicsDeviceManager.SupportedOrientations & DisplayOrientation.Portrait) == 0) { return; } var manager = _game.graphicsDeviceManager; manager.PreferredBackBufferWidth = width; manager.PreferredBackBufferHeight = height; if (manager.GraphicsDevice != null) { manager.GraphicsDevice.Viewport = new Viewport(0, 0, width, height); } _gameWindow.ChangeClientBounds(new Rectangle(0, 0, width, height)); manager.ApplyChanges(); SurfaceChanged(holder, format, width, height); Android.Util.Log.Debug("MonoGame", "MonoGameAndroidGameView.SurfaceChanged: format = " + format + ", width = " + width + ", height = " + height); if (_game.GraphicsDevice != null) { _game.graphicsDeviceManager.ResetClientBounds(); } }
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(); }
public void SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int width, int height) { System.Diagnostics.Debug.WriteLine("SurfaceDestroyed"); if (width > height) { //TODO: flag that we're landscape } else { //TODO: flag that we're portrait } }
public void SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int width, int height) { if (holder == null) { return; } if (Preview != null && !IsPreviewing) { //TODO: Reconnect is failing when switching back into the application. Preview = camera; Preview.Reconnect(); Preview.Lock(); Preview.EnableShutterSound(false); Preview.StartPreview(); IsPreviewing = true; } if (Preview != null) { try { //var parameters = Preview.GetParameters(); //var previewSize = Preview.GetParameters().SupportedPreviewSizes[0]; //parameters.SetPreviewSize(previewSize.Width, previewSize.Height); //parameters.PictureFormat = Android.Graphics.ImageFormatType.Jpeg; //Preview.SetParameters(parameters); } catch (Exception exception) { SentrySdk.CaptureException(exception); } 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; } } }
public void SurfaceChanged(ISurfaceHolder surfaceHolder, Android.Graphics.Format i, int width, int height) { if (mSurfaceView.mWidth != width) { mSurfaceView.mWidth = width; mSurfaceView.mSizeChange.Set(true); } if (mSurfaceView.mHeight != height) { mSurfaceView.mHeight = height; mSurfaceView.mSizeChange.Set(true); } }
public void SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int w, int h) { // start preview with new settings try { mCamera.SetPreviewDisplay(holder); mCamera.StartPreview(); } catch (Exception e) { // intentionally left blank for a test } }
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 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(); }
/// <summary> /// Surfaces the changed. /// </summary> /// <param name="holder">The holder.</param> /// <param name="format">The format.</param> /// <param name="w">The w.</param> /// <param name="h">The h.</param> public void SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int w, int h) { CameraWithId.Item2.StartPreview(); var postRotation = CameraHelper.GetCameraDisplayOrientation(CameraWithId.Item1); CameraWithId.Item2.SetDisplayOrientation(postRotation); var parameters = CameraWithId.Item2.GetParameters(); var profile = CamcorderProfile.Get(CameraWithId.Item1, CamcorderQuality.Q480p); parameters.SetPreviewSize(profile.VideoFrameWidth, profile.VideoFrameHeight); RequestLayout(); CameraWithId.Item2.SetParameters(parameters); }
public void SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int w, int h) { if (holder.Surface == null) { return; // preview surface does not exist. } try { camera.StopPreview(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("DHB:CameraPreview:SurfaceChanged exception:" + e.ToString()); } // @todo camera reformat try { camera.SetPreviewDisplay(this.Holder); // this is what the example has. it is NOT the passed in holder. is this an error? camera.StartPreview(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("DHB:CameraPreview:SurfaceChanged exception:" + e.ToString()); } }
public void SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int width, int height) { var parameters = Preview.GetParameters(); //var supportedFocusModes = Preview.GetParameters().SupportedFocusModes; 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; } //========= /*parameters.Set("s3d-prv-frame-layout", "none"); * parameters.Set("s3d-cap-frame-layout", "none"); * parameters.Set("iso", "auto"); * parameters.Set("Contrast", 100); * parameters.Set("Brightness", 50); * parameters.Set("Saturation", 100); * parameters.Set("Sharpness", 100);*/ parameters.Set("jpeg-quality", 100); //parameters.SetPictureSize(800, 600); //========= parameters.FocusMode = Camera.Parameters.FocusModeContinuousPicture; Preview.SetParameters(parameters); //Preview.SetPreviewCallbackWithBuffer(this); Preview.StartPreview(); IsPreviewing = true; //Preview.TakePicture(null,null,null,null); }
public void SurfaceChanged(ISurfaceHolder holder, [GeneratedEnum] Android.Graphics.Format format, int width, int height) { if (activity.previewing) { camera.StopPreview(); activity.previewing = false; } if (camera != null) { try { camera.SetPreviewDisplay(activity.surfaceHolder); camera.StartPreview(); activity.previewing = true; } catch (IOException e) { // TODO Auto-generated catch block e.PrintStackTrace(); } } }
public void SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int w, int h) { Console.WriteLine("SurfaceChanged"); }
public void SurfaceChanged(ISurfaceHolder holder, [GeneratedEnum] Android.Graphics.Format format, int width, int height) { }
public void SurfaceChanged(ISurfaceHolder holder, Android.Graphics.Format format, int width, int height) { //surface changed }