public async void OnSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { if (ContextCompat.CheckSelfPermission(Activity, Manifest.Permission.Camera) != Permission.Granted) { ActivityCompat.RequestPermissions(Activity, new string[] { Manifest.Permission.Camera }, 50); await(Element as CameraPage).Navigation.PopAsync(); //(Element as CameraPage).Cancel(); } else { decimal aspect = 0; camera = Android.Hardware.Camera.Open(); var parameters = camera.GetParameters(); if (GetOrientation()) { aspect = ((decimal)height) / ((decimal)width); } else { aspect = ((decimal)width) / ((decimal)height); } var previewSize = parameters.SupportedPreviewSizes .OrderBy(s => System.Math.Abs(s.Width / (decimal)s.Height - aspect)) .First(); parameters.SetPreviewSize(previewSize.Width, previewSize.Height); camera.SetParameters(parameters); camera.SetPreviewTexture(surface); StartCamera(); } }
public async void OnAutoFocus(bool success, Android.Hardware.Camera camera) { var bytes = await TakePhoto(); if (GetOrientation()) { bytes = ResizeImage(bytes, 720, 1280); } else { bytes = ResizeImage(bytes, 1280, 720); } if (type == "Photo") { (Element as CameraPage).SetPhotoResult(bytes, liveView.Bitmap.Width, liveView.Bitmap.Height); } else if (type == "DetectText") { (Element as CameraPage).SetScan(bytes, liveView.Bitmap.Width, liveView.Bitmap.Height); } else if (type == "PhotoIspection") { if (clickNameBtn == "capturePhotoInspectionButton") { (Element as CameraPage).SetPhotoinspectionResult(bytes, liveView.Bitmap.Width, liveView.Bitmap.Height); } else if (clickNameBtn == "capturePhotoInspectionButton1") { (Element as CameraPage).SetPhotoResult(bytes, liveView.Bitmap.Width, liveView.Bitmap.Height); } } progressBar.Visibility = Android.Views.ViewStates.Invisible; capturePhotoButton.Visibility = Android.Views.ViewStates.Visible; isFocus = false; }
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 StopCamera() { camera.SetPreviewCallback(null); camera.StopPreview(); camera.Release(); camera = null; }
public void OnPreviewFrame(byte[] data, Android.Hardware.Camera camera) { Bitmap capturedScreen = convertYuvByteArrayToBitmap(data, camera); if (capturedScreen != null) { using (MemoryStream ms = new MemoryStream()) { capturedScreen.Compress(Android.Graphics.Bitmap.CompressFormat.Jpeg, int.Parse(MainValues.quality), ms); byte[] live = ForegroundService._globalService.MyDataPacker("VID", ms.ToArray(), ID); try { if (camSock != null) { camSock.Send(live, 0, live.Length, SocketFlags.None); System.Threading.Tasks.Task.Delay(1).Wait(); } } catch (Exception) { //Android.Widget.Toast.MakeText(MainActivity.global_activity, ex.Message, Android.Widget.ToastLength.Long).Show(); } } } }
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); } }
// AutoFocusのコールバック public void OnAutoFocus(bool success, AndroidCamera camera) { if (isTakeEnabled) { m_Camera.TakePicture(null, null, this); } }
public void OnPreviewFrame(byte[] data, Android.Hardware.Camera camera) { Bitmap capturedScreen = convertYuvByteArrayToBitmap(data, camera); if (capturedScreen != null) { using (capturedScreen) { using (MemoryStream ms = new MemoryStream()) { capturedScreen.Compress(Bitmap.CompressFormat.Jpeg, int.Parse(MainValues.quality), ms); byte[] live = ForegroundService._globalService.MyDataPacker("VID", ms.ToArray(), ID); try { if (camSock != null) { camSock.Send(live, 0, live.Length, SocketFlags.None); System.Threading.Tasks.Task.Delay(1).Wait(); System.Diagnostics.Debug.WriteLine("WEBCAM SENDING"); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("WEBCAM " + ex.Message); } } } } else { System.Diagnostics.Debug.WriteLine("NULL YUV ARAY"); } }
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 { } } }
public void OnPictureTaken(byte[] data, Camera camera) { StopCameraPreview(); // better do that because we don't need a preview right now // create a Bitmap from the raw data Bitmap picture = BitmapFactory.DecodeByteArray(data, 0, data.Length); Activity parentActivity = (Activity)this.Context; int rotation = (int)parentActivity.Window.WindowManager.DefaultDisplay.Rotation; if (rotation == (int)SurfaceOrientation.Rotation0 || rotation == (int)SurfaceOrientation.Rotation180) { Matrix matrix = new Matrix(); matrix.PostRotate(90); // create a rotated version and replace the original bitmap picture = Bitmap.CreateBitmap(picture, 0, 0, picture.Width, picture.Height, matrix, true); } // save to media library MediaStore.Images.Media.InsertImage(parentActivity.ContentResolver, picture, $"{Guid.NewGuid()}", string.Empty); // show a message Toast toast = Toast.MakeText(parentActivity, "Picture saved to the media library", ToastLength.Long); toast.Show(); StartCameraPreview(Holder); }
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); } }
static Task ToggleTorchAsync(bool switchOn) { return(Task.Run(() => { lock (locker) { if (Platform.HasApiLevel(BuildVersionCodes.M) && !AlwaysUseCameraApi) { var cameraManager = Platform.CameraManager; foreach (var id in cameraManager.GetCameraIdList()) { var hasFlash = cameraManager.GetCameraCharacteristics(id).Get(CameraCharacteristics.FlashInfoAvailable); if (Java.Lang.Boolean.True.Equals(hasFlash)) { cameraManager.SetTorchMode(id, switchOn); break; } } } else { if (camera == null) { if (surface == null) { surface = new SurfaceTexture(0); } #pragma warning disable CS0618 // Camera types are deprecated in Android 10+ camera = Camera.Open(); // Nexus 5 and some devices require a preview texture camera.SetPreviewTexture(surface); } var param = camera.GetParameters(); // Deprecated in an earlier android version param.FlashMode = switchOn ? Camera.Parameters.FlashModeTorch : Camera.Parameters.FlashModeOff; camera.SetParameters(param); if (switchOn) { camera.StartPreview(); } else { camera.StopPreview(); camera.Release(); camera.Dispose(); #pragma warning restore CS0618 // Type or member is obsolete camera = null; surface.Dispose(); surface = null; } } } })); }
private void InitView(Android.Hardware.Camera camera) { this.camera = camera; camera.SetDisplayOrientation(90); Holder.AddCallback(this); Holder.SetType(SurfaceType.PushBuffers); }
public void OnPreviewFrame(byte[] data, Android.Hardware.Camera camera) { try { yuvImage = new YuvImage(data, ImageFormatType.Nv21, previewWidth, previewHeight, null); stride = yuvImage.GetStrides(); try { if (isReady) { if (backgroundHandler != null) { isReady = false; Message msg = new Message(); msg.What = 100; msg.Obj = yuvImage; backgroundHandler.SendMessage(msg); backgroundHandler.Post(() => { //tvResult.Text = result; }); } } } catch (BarcodeReaderException e) { e.PrintStackTrace(); } } catch (System.IO.IOException) { } }
public void OnAutoFocus(bool success, Android.Hardware.Camera camera) { var parameters = camera.GetParameters(); var supportedFocusModes = parameters.SupportedFocusModes; var supportedFocusMode = cameraPage.GetSupportedFocusMode(); parameters.FocusMode = supportedFocusMode; if (supportedFocusModes != null && supportedFocusModes.Any()) { if (parameters.MaxNumFocusAreas > 0) { parameters.FocusAreas = null; } if (success) { TextView focusIndicatorTV = this.cameraPage.focusIndicator; focusIndicatorTV.SetX(tapX); focusIndicatorTV.SetY(tapY); focusIndicatorTV.Visibility = ViewStates.Visible; } else { TextView focusIndicatorTV = this.cameraPage.focusIndicator; focusIndicatorTV.Visibility = ViewStates.Gone; } camera.SetParameters(parameters); camera.StartPreview(); } }
private void SwitchFlash(bool On) { try { Android.Hardware.Camera _camer = GetCamera(); if (On) { if (_camer != null) { var prms = _camer.GetParameters(); prms.FlashMode = Android.Hardware.Camera.Parameters.FlashModeTorch; _camer.SetParameters(prms); } } else { if (_camer != null) { var prms = _camer.GetParameters(); prms.FlashMode = Android.Hardware.Camera.Parameters.FlashModeOff; _camer.SetParameters(prms); } } } catch (Exception es) { Log.Info("Release", "txtRecognizer.SetProcessor " + es.Message); } }
public async Task GetPhoto() { _camera = Camera.Open(); var parameters = _camera.GetParameters(); var sizes = parameters.SupportedPictureSizes; int index = 0; for (int i = 0; i < sizes.Count; i++) { if (sizes[i].Width > 1200 && sizes[i].Width < 1300) { index = i; } } parameters.SetPictureSize(sizes[index].Width, sizes[index].Height); parameters.SetRotation(90); parameters.SceneMode = Camera.Parameters.SceneModeAuto; parameters.WhiteBalance = Camera.Parameters.WhiteBalanceAuto; parameters.FocusMode = Camera.Parameters.FocusModeContinuousPicture; parameters.PictureFormat = ImageFormatType.Jpeg; parameters.JpegQuality = 100; _camera.SetParameters(parameters); _camera.SetPreviewCallback(this); _camera.Lock(); SurfaceTexture st = new SurfaceTexture(100); _camera.SetPreviewTexture(st); _camera.StartPreview(); await TakePicture(); }
public void OnPreviewFrame(byte[] data, Android.Hardware.Camera camera) { try { System.Console.WriteLine("start create Image"); yuvImage = new YuvImage(data, ImageFormatType.Nv21, previewWidth, previewHeight, null); stride = yuvImage.GetStrides(); try { if (isReady) { if (backgroundHandler != null) { isReady = false; Message msg = new Message(); msg.What = 100; msg.Obj = yuvImage; backgroundHandler.SendMessage(msg); } } } catch (BarcodeReaderException e) { e.PrintStackTrace(); } } catch (System.IO.IOException) { } }
public void TurnOff() { if (camera == null) { camera = Camera.Open(); } if (camera == null) { 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); } }
public void OnSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { //If authorisation not granted for camera if (ContextCompat.CheckSelfPermission(CurrentContext, Manifest.Permission.Camera) != Permission.Granted) { //ask for authorisation ActivityCompat.RequestPermissions(CurrentContext, new String[] { Manifest.Permission.Camera }, 50); } else { camera = Android.Hardware.Camera.Open(); var parameters = camera.GetParameters(); var aspect = ((decimal)height) / ((decimal)width); // Find the preview aspect ratio that is closest to the surface aspect var previewSize = parameters.SupportedPreviewSizes .OrderBy(s => Math.Abs(s.Width / (decimal)s.Height - aspect)) .First(); System.Diagnostics.Debug.WriteLine($"Preview sizes: {parameters.SupportedPreviewSizes.Count}"); parameters.SetPreviewSize(previewSize.Width, previewSize.Height); camera.SetParameters(parameters); camera.SetPreviewTexture(surface); StartCamera(); } }
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) { } } }
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 OnPictureTaken(byte[] data, Android.Hardware.Camera camera) { Bitmap bitmapPicture = BitmapFactory.DecodeByteArray(data, 0, data.Length); bitmapPicture = Bitmap.CreateScaledBitmap(bitmapPicture, Resources.DisplayMetrics.WidthPixels, Resources.DisplayMetrics.HeightPixels / 2, false); Photo picture = new Photo(bitmapPicture, ".png", sessionPath); }
public void SurfaceCreated(ISurfaceHolder holder) { if ((!isRecording) && (!isTakingPictures)) { camera = Android.Hardware.Camera.Open(); } }
public void OnSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { _camera = Camera.Open(FindBackFacingCamera()); //_textureView.LayoutParameters = new FrameLayout.LayoutParams(width, WallpaperDesiredMinimumHeight); var parameters = _camera.GetParameters(); try { var aspect = ((decimal)height) / ((decimal)width); var previewSize = parameters.SupportedPreviewSizes .OrderBy(s => Math.Abs(s.Width / (decimal)s.Height - aspect)) .First(); parameters.SetPreviewSize(previewSize.Width, previewSize.Height); parameters.FocusMode = Camera.Parameters.FocusModeContinuousPicture; _camera.SetParameters(parameters); _camera.SetPreviewTexture(surface); StartCamera(); } catch (Java.IO.IOException ex) { // todo handle error here System.Diagnostics.Debug.WriteLine(ex); } }
// シャッターを切った時のコールバック public void OnPictureTaken(byte[] data, AndroidCamera camera) { try { var SaveDir = new Java.IO.File(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryDcim), "Camera"); if (!SaveDir.Exists()) { SaveDir.Mkdir(); } // 非同期で画像の回転・保存・アルバムへの登録 Task.Run(async() => { // 保存ディレクトリに入ってるファイル数をカウント var Files = SaveDir.List(); int count = 0; foreach (var tmp in Files) { count++; } Matrix matrix = new Matrix(); // 回転用の行列 matrix.SetRotate(90 - DetectScreenOrientation()); Bitmap original = BitmapFactory.DecodeByteArray(data, 0, data.Length); Bitmap rotated = Bitmap.CreateBitmap(original, 0, 0, original.Width, original.Height, matrix, true); var FileName = new Java.IO.File(SaveDir, "DCIM_" + (count + 1) + ".jpg"); // ファイルをストレージに保存 FileStream stream = new FileStream(FileName.ToString(), FileMode.CreateNew); await rotated.CompressAsync(Bitmap.CompressFormat.Jpeg, 90, stream); stream.Close(); Android.Media.ExifInterface Exif = new ExifInterface(FileName.ToString()); Exif.SetAttribute(ExifInterface.TagGpsLatitude, Latitude); Exif.SetAttribute(ExifInterface.TagGpsLongitude, Longitude); Exif.SetAttribute(ExifInterface.TagGpsLatitudeRef, "N"); Exif.SetAttribute(ExifInterface.TagGpsLongitudeRef, "E"); Exif.SaveAttributes(); // 保存したファイルをアルバムに登録 string[] FilePath = { Environment.GetExternalStoragePublicDirectory(Environment.DirectoryDcim) + "/Camera/" + "DCIM_" + (count + 1) + ".jpg" }; string[] mimeType = { "image/jpeg" }; MediaScannerConnection.ScanFile(ApplicationContext, FilePath, mimeType, null); RunOnUiThread(() => { Toast.MakeText(ApplicationContext, "保存しました\n" + FileName, ToastLength.Short).Show(); }); original.Recycle(); rotated.Recycle(); isTakeEnabled = false; }); m_Camera.StartPreview(); } catch (Exception e) { Console.WriteLine(e.Message); } }
public CameraPreview(Activity context, Android.Hardware.Camera camera) : base(context) { _camera = camera; _activity = context; _holder = this.Holder; _holder.AddCallback(this); //_holder.SetType(SurfaceType.PushBuffers); }
public void OnPictureTaken(byte[] data, Android.Hardware.Camera camera) { Bitmap newBitmap = _Context.ProcessImage(data, camera); //linearButton.Enabled = true; System.GC.Collect(); _Context.trophyFragment.CapturedBitmap(newBitmap); }
public void SurfaceCreated (ISurfaceHolder holder) { if (camera == null) { this.camera = Android.Hardware.Camera.Open (); this.camera.SetPreviewDisplay (holder); this.camera.SetPreviewCallback (this); this.camera.StartPreview (); } }
public CameraPreview(Context context, Android.Hardware.Camera camera) : base(context) { _mCamera = camera; Holder.AddCallback(this); _mSupportedPreviewSizes = _mCamera.GetParameters().SupportedPreviewSizes.ToList(); _mSupportedPictureSizes = _mCamera.GetParameters().SupportedPictureSizes.ToList(); Holder.SetType(SurfaceType.PushBuffers); }
private void StopCamera() { if (_camera != null) { _camera.StopPreview(); _camera.Release(); _camera = null; } }
public bool OnSurfaceTextureDestroyed(SurfaceTexture surface) { if (_camera != null) { _camera.StopPreview(); _camera.Release(); _camera = null; } return true; }
private void StartCameraPreview(SurfaceTexture surface, int width, int height) { try { if (_camera != null) { _camera.Release(); _camera.Reconnect(); } else { _camera = Camera.Open(); SetAutoFocus(_camera); } } catch (Exception ex) { return; } var cameraParameters = _camera.GetParameters(); cameraParameters.SetRotation(90); // var previewSize = GetOptimalPreviewSize(cameraParameters.SupportedPictureSizes, width, height); var previewSize = cameraParameters.PictureSize; cameraParameters.SetPreviewSize(previewSize.Width, previewSize.Height); _camera.SetParameters(cameraParameters); _textureView.LayoutParameters = new FrameLayout.LayoutParams( previewSize.Width, previewSize.Height, GravityFlags.Center); try { _camera.SetPreviewTexture(surface); _camera.StartPreview(); _safeToTakePicture = true; } catch (IOException ex) { return; } _textureView.Rotation = 90.0f; _textureView.Alpha = 0.5f; }
public void OnPictureTaken(byte[] data, Camera camera) { var fileName = GetImagePath(); WriteDataToFile(fileName, data); AddPictureToGallery(fileName); }
public override bool OnOptionsItemSelected (IMenuItem item) { // Handle item selection switch (item.ItemId) { case Resource.Id.switch_cam: // Release this camera -> mCameraCurrentlyLocked if (mCamera != null) { mCamera.StopPreview (); mPreview.SetCamera (null); mCamera.Release (); mCamera = null; } // Acquire the next camera and request Preview to reconfigure // parameters. mCamera = Camera.Open ((mCameraCurrentlyLocked + 1) % mNumberOfCameras); mCameraCurrentlyLocked = (mCameraCurrentlyLocked + 1) % mNumberOfCameras; mPreview.SwitchCamera (mCamera); // Start the preview mCamera.StartPreview(); return true; case Android.Resource.Id.Home: Intent intent = new Intent (this.Activity, typeof (MainActivity)); intent.AddFlags (ActivityFlags.ClearTop | ActivityFlags.SingleTop); StartActivity (intent); goto default; default: return base.OnOptionsItemSelected (item); } }
public void OnPictureTaken(byte[] data, Camera camera) { FileOutputStream outStream = null; File dataDir = Android.OS.Environment.ExternalStorageDirectory; if (data != null) { try { outStream = new FileOutputStream(dataDir + "/" + "Photo.jpg"); outStream.Write(data); outStream.Close(); this.Dismiss(); } catch (FileNotFoundException e) { System.Console.Out.WriteLine(e.Message); } catch (IOException ie) { System.Console.Out.WriteLine(ie.Message); } } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.VideoMessage); SurfaceView surface = FindViewById<SurfaceView>(Resource.Id.surfaceView1); double surfaceSize = wowZapp.LaffOutOut.Singleton.ScreenYHeight * .66; ImageButton record = FindViewById<ImageButton>(Resource.Id.btnRecord); ImageButton stop = FindViewById<ImageButton>(Resource.Id.btnStop); ImageButton pause = FindViewById<ImageButton>(Resource.Id.btnPause); ImageButton play = FindViewById<ImageButton>(Resource.Id.btnPlay); ImageButton edit = FindViewById<ImageButton>(Resource.Id.btnEdit); recordTimer = new System.Timers.Timer(); recordTimer.Interval = 1000; recordTimer.Elapsed += (object sender, System.Timers.ElapsedEventArgs e) => timerElapsed(sender, e); mediaPlayer = new Android.Media.MediaPlayer(); progress = FindViewById<ProgressBar>(Resource.Id.progressBar1); timeLeft = FindViewById<TextView>(Resource.Id.textTimeLeft); Context context = timeLeft.Context; timeString = context.Resources.GetString(Resource.String.videoSeconds); timeLeft.Text = timeRemain.ToString() + " " + timeString; //CamcorderProfile camProf = new CamcorderProfile(); //fps = camProf.VideoFrameRate; camera = null; ImageButton returnBack = FindViewById<ImageButton>(Resource.Id.imgBack); returnBack.Tag = 0; ImageButton flipView = FindViewById<ImageButton>(Resource.Id.imageRotate); flipView.Tag = 1; ImageButton returnHome = FindViewById<ImageButton>(Resource.Id.imgHome); returnHome.Tag = 2; LinearLayout bottom = FindViewById<LinearLayout>(Resource.Id.bottomHolder); ImageButton[] btn = new ImageButton[3]; btn [0] = returnBack; btn [2] = returnHome; btn [1] = flipView; ImageHelper.setupButtonsPosition(btn, bottom, context); record.Click += delegate { if (!recording && !playing) startRecording(); }; stop.Click += delegate { if (recording) stopRecording(); if (playing) stopPlaying(); }; play.Click += delegate { if (!recording) startPlayback(); }; edit.Click += delegate { Intent i = new Intent(this, typeof(EditVideo)); i.PutExtra("filename", System.IO.Path.Combine(Android.OS.Environment.ExternalStorageDirectory.ToString(), "myvideooutputfile.mp4")); i.PutExtra("fps", fps); i.PutExtra("duration", counter); StartActivityForResult(i, EDIT); }; returnBack.Click += delegate { Finish(); }; returnHome.Click += delegate { Intent i = new Intent(this, typeof(Main.HomeActivity)); i.AddFlags(ActivityFlags.ClearTop); StartActivity(i); }; holder = surface.Holder; holder.AddCallback(this); holder.SetType(Android.Views.SurfaceType.PushBuffers); }
private void correctCameras(int cameras) { int result = 0; Android.Hardware.Camera.CameraInfo cameraInfo = new Android.Hardware.Camera.CameraInfo(); Android.Hardware.Camera.GetCameraInfo(cameras, cameraInfo); int rotation = WindowManager.DefaultDisplay.Orientation; int degrees = rotation; if (cameraInfo.Facing == Android.Hardware.CameraFacing.Front) { result = (cameraInfo.Orientation + degrees) % 360; result = (360 - result) % 360; try { if (isLocked == true) camera.Unlock(); camera = Android.Hardware.Camera.Open(cameras); } catch (Java.Lang.RuntimeException ex) { RunOnUiThread(delegate { GeneralUtils.Alert(context, Application.Context.Resources.GetString(Resource.String.commonError), Application.Context.Resources.GetString(Resource.String.photoNoConnection)); }); #if DEBUG System.Diagnostics.Debug.WriteLine("Exception flung {0}", ex.ToString()); #endif } } else { result = (cameraInfo.Orientation - degrees + 360) % 360; try { if (isLocked == true) camera.Unlock(); camera = Android.Hardware.Camera.Open(cameras); } catch (Java.Lang.RuntimeException ex) { RunOnUiThread(delegate { GeneralUtils.Alert(context, Application.Context.Resources.GetString(Resource.String.commonError), Application.Context.Resources.GetString(Resource.String.photoNoConnection)); }); #if DEBUG System.Diagnostics.Debug.WriteLine("Exception flung {0}", ex.ToString()); #endif } } if (camera != null) { RunOnUiThread(delegate { camera.SetDisplayOrientation(result); camera.StartPreview(); camera.Lock(); }); isLocked = true; } }
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 override void OnResume() { base.OnResume (); // Open the default i.e. the first rear facing camera. mCamera = Camera.Open (mDefaultCameraId); mCameraCurrentlyLocked = mDefaultCameraId; mPreview.SetCamera (mCamera); }
public 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.SetCamera (null); mCamera.Release (); mCamera = null; } }
public void OnPreviewFrame(byte[] data, Camera camera) { //TODO: NV21 to RGB? lastFrame = data; }
public void OnPreviewFrame(byte[] data, Camera camera) { }
private static void SetAutoFocus(Camera camera) { var parameters = camera.GetParameters(); var focusModes = parameters.SupportedFocusModes; if (focusModes.Contains(Camera.Parameters.FocusModeAuto)) parameters.FocusMode = Camera.Parameters.FocusModeAuto; camera.SetParameters(parameters); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); var metrics = new DisplayMetrics(); WindowManager.DefaultDisplay.GetRealMetrics(metrics); ScreenX = metrics.WidthPixels; ScreenY = metrics.HeightPixels; number = 0; SetContentView(Resource.Layout.CameraTakePicScreen); isRunning = false; var header = FindViewById<TextView>(Resource.Id.txtFirstScreenHeader); var btns = FindViewById<ImageView>(Resource.Id.imgNewUserHeader); var relLayout = FindViewById<RelativeLayout>(Resource.Id.relativeLayout1); ImageHelper.setupTopPanel(btns, header, relLayout, header.Context); Header.headertext = Application.Context.Resources.GetString(Resource.String.photoTitle); Header.fontsize = 32f; ImageHelper.fontSizeInfo(header.Context); header.SetTextSize(Android.Util.ComplexUnitType.Dip, Header.fontsize); header.Text = Header.headertext; var surface = FindViewById<SurfaceView>(Resource.Id.surfaceCameraView); holder = surface.Holder; holder.AddCallback(this); context = surface.Context; var takePicture = FindViewById<ImageButton>(Resource.Id.btnCamera); takePicture.Tag = 1; var flipView = FindViewById<ImageButton>(Resource.Id.imgFlipView); flipView.Tag = 2; var returnBack = FindViewById<ImageButton>(Resource.Id.imgBack); returnBack.Tag = 0; var bottom = FindViewById<LinearLayout>(Resource.Id.bottomHolder); var btn = new ImageButton[3]; btn[0] = returnBack; btn[1] = takePicture; btn[2] = flipView; ImageHelper.setupButtonsPosition(btn, bottom, context); var cameraInfo = new Android.Hardware.Camera.CameraInfo(); camera = null; int cameraCount = Android.Hardware.Camera.NumberOfCameras; if (cameraCount == 1) flipView.Visibility = ViewStates.Invisible; else { flipView.Click += delegate { if (isRunning) { camera.StopPreview(); isRunning = false; camera.Unlock(); if (cameraCount > 1 && camID < cameraCount - 1) camID++; else camID--; camera = Android.Hardware.Camera.Open(camID); isRunning = true; camera.Lock(); camera.StartPreview(); } }; } takePicture.Click += delegate { var p = camera.GetParameters(); p.PictureFormat = Android.Graphics.ImageFormatType.Jpeg; camera.SetParameters(p); camera.TakePicture(this, this, this); }; returnBack.Click += (object sender, EventArgs e) => { var resultData = new Intent(); resultData.PutExtra("filename", fullFilename); SetResult(!string.IsNullOrEmpty(fullFilename) ? Result.Ok : Result.Canceled, resultData); Finish(); }; }
private void openFrontFacingCamera() { int cameraCount = 0; var cameraInfo = new Android.Hardware.Camera.CameraInfo(); cameraCount = Android.Hardware.Camera.NumberOfCameras; int result = 0; for (int camIdx = 0; camIdx < cameraCount; ++camIdx) { Android.Hardware.Camera.GetCameraInfo(camIdx, cameraInfo); var rotation = WindowManager.DefaultDisplay.Rotation; int degrees = 0; camID = camIdx; 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; } if (cameraInfo.Facing == Android.Hardware.CameraFacing.Front) { result = (cameraInfo.Orientation + degrees) % 360; result = (360 - result) % 360; try { camera = Android.Hardware.Camera.Open(camIdx); } catch (Java.Lang.RuntimeException) { RunOnUiThread(() => GeneralUtils.Alert(context, Application.Context.Resources.GetString(Resource.String.commonError), Application.Context.Resources.GetString(Resource.String.photoNoConnection))); } } else result = (cameraInfo.Orientation - degrees + 360) % 360; } if (camera != null) camera.SetDisplayOrientation(result); }
public void SetCamera (Camera camera) { mCamera = camera; if (mCamera != null) { mSupportedPreviewSizes = mCamera.GetParameters () .SupportedPreviewSizes; RequestLayout (); } }
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) { } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); number = 0; SetContentView(Resource.Layout.CameraTakePicScreen); isRunning = false; TextView header = FindViewById<TextView>(Resource.Id.txtFirstScreenHeader); ImageView btns = FindViewById<ImageView>(Resource.Id.imgNewUserHeader); RelativeLayout relLayout = FindViewById<RelativeLayout>(Resource.Id.relativeLayout1); ImageHelper.setupTopPanel(btns, header, relLayout, header.Context); Header.headertext = Application.Context.Resources.GetString(Resource.String.photoTitle); Header.fontsize = 36f; ImageHelper.fontSizeInfo(header.Context); header.SetTextSize(Android.Util.ComplexUnitType.Dip, Header.fontsize); header.Text = Header.headertext; SurfaceView surface = FindViewById<SurfaceView>(Resource.Id.surfaceCameraView); holder = surface.Holder; holder.AddCallback(this); holder.SetType(Android.Views.SurfaceType.PushBuffers); context = surface.Context; ImageButton takePicture = FindViewById<ImageButton>(Resource.Id.btnCamera); takePicture.Tag = 1; ImageButton flipView = FindViewById<ImageButton>(Resource.Id.imgFlipView); flipView.Tag = 2; ImageButton returnBack = FindViewById<ImageButton>(Resource.Id.imgBack); returnBack.Tag = 0; LinearLayout bottom = FindViewById<LinearLayout>(Resource.Id.bottomHolder); ImageButton[] btn = new ImageButton[3]; btn [0] = returnBack; btn [1] = takePicture; btn [2] = flipView; ImageHelper.setupButtonsPosition(btn, bottom, context); int back = (int)Android.Hardware.CameraFacing.Back; int front = (int)Android.Hardware.CameraFacing.Front; Android.Hardware.Camera.CameraInfo cameraInfo = new Android.Hardware.Camera.CameraInfo(); camera = null; int cameraCount = Android.Hardware.Camera.NumberOfCameras; if (cameraCount == 1) flipView.Visibility = ViewStates.Invisible; else { flipView.Click += delegate { if (isRunning) { camera.StopPreview(); isRunning = false; camera.Unlock(); //camera.Release(); if (cameraCount > 1 && camID < cameraCount - 1) camID++; else camID--; camera = Android.Hardware.Camera.Open(camID); isRunning = true; camera.Lock(); camera.StartPreview(); } }; } takePicture.Click += delegate { Android.Hardware.Camera.Parameters p = camera.GetParameters(); p.PictureFormat = Android.Graphics.ImageFormatType.Jpeg; camera.SetParameters(p); camera.TakePicture(this, this, this); }; returnBack.Click += (object sender, EventArgs e) => { Intent resultData = new Intent(); resultData.PutExtra("filename", fullFilename); if (fullFilename != "") SetResult(Result.Ok, resultData); else SetResult(Result.Canceled, resultData); Finish(); }; }