Ejemplo n.º 1
0
        private void HandleZoom(MotionEvent e, Android.Hardware.Camera.Parameters parameters)
        {
            var maxZoom = parameters.MaxZoom;
            var zoom    = parameters.Zoom;
            var newDist = GetFingerSpacing(e);

            if (newDist > _mDist)
            {
                //zoom in
                if (zoom < maxZoom)
                {
                    zoom++;
                }
            }
            else if (newDist < _mDist)
            {
                //zoom out
                if (zoom > 0)
                {
                    zoom--;
                }
            }

            _mDist          = newDist;
            parameters.Zoom = zoom;
            _camera.SetParameters(parameters);
        }
Ejemplo n.º 2
0
        public static Android.Hardware.Camera.Size GetOptimalPictureSize(this Android.Hardware.Camera.Parameters p, int w)
        {
            var sizes  = p.SupportedPictureSizes;
            int offset = Integer.MaxValue;

            Android.Hardware.Camera.Size rs = null;

            if (sizes != null)
            {
                foreach (var size in sizes)
                {
                    if (size.Width >= size.Height)
                    {
                        int curSize = size.Width;

                        if (size.Height >= w && size.Height >= w && (curSize - w) < offset)
                        {
                            offset = curSize - w;
                            rs     = size;
                        }
                    }
                }
            }

            return(rs);
        }
Ejemplo n.º 3
0
        private void UpdateCameraAspect()
        {
            try
            {
                Android.Hardware.Camera.Parameters camParams = camera.GetParameters();
                Android.Hardware.Camera.CameraInfo info      = new Android.Hardware.Camera.CameraInfo();
                Android.Hardware.Camera.GetCameraInfo((int)Android.Hardware.CameraFacing.Back, info);

                Android.Hardware.Camera.Size size = GetOptimalPreviewSize(camParams.SupportedPreviewSizes, width, height);

                camParams.SetPreviewSize(size.Width, size.Height);

                int rotation = (info.Orientation + 360) % 360;

                camParams.SetRotation(rotation);

                if (camParams.SupportedFocusModes.Contains(Android.Hardware.Camera.Parameters.FocusModeContinuousPicture))
                {
                    camParams.FocusMode = Android.Hardware.Camera.Parameters.FocusModeContinuousPicture;
                }

                camera.SetParameters(camParams);
            }
            catch (System.Exception e)
            {
                System.Console.WriteLine(e.Message);
            }
        }
Ejemplo n.º 4
0
        public void FlashParam(Android.Hardware.Camera.Parameters prm)
        {
            IList <string> supportedFlashModes = prm.SupportedFlashModes;

            if (supportedFlashModes != null)
            {
                if (supportedFlashModes.Contains(Android.Hardware.Camera.Parameters.FlashModeTorch))
                {
                    prm.FlashMode = Android.Hardware.Camera.Parameters.FlashModeTorch;
                }
                else
                {
                    if (supportedFlashModes.Contains(Android.Hardware.Camera.Parameters.FlashModeRedEye))
                    {
                        prm.FlashMode = Android.Hardware.Camera.Parameters.FlashModeRedEye;
                    }
                    else
                    {
                        if (supportedFlashModes.Contains(Android.Hardware.Camera.Parameters.FlashModeOn))
                        {
                            prm.FlashMode = Android.Hardware.Camera.Parameters.FlashModeOn;
                        }
                        else
                        {
                            if (supportedFlashModes.Contains(Android.Hardware.Camera.Parameters.FlashModeAuto))
                            {
                                prm.FlashMode = Android.Hardware.Camera.Parameters.FlashModeAuto;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        /**
         * Checks if the requested resolution is supported by the camera.
         * If not, it modifies it by supported parameters.
         **/
        public static VideoQuality determineClosestSupportedResolution(Android.Hardware.Camera.Parameters parameters, VideoQuality quality)
        {
            VideoQuality v       = quality.clone();
            int          minDist = Integer.MaxValue;

            System.String supportedSizesStr = "Supported resolutions: ";
            IList <Android.Hardware.Camera.Size> supportedSizes = parameters.SupportedPreviewSizes;

            //for (Iterator<Size> it = supportedSizes.En...iterator(); it.hasNext();)
            foreach (Android.Hardware.Camera.Size size in supportedSizes)
            {
                //  supportedSizesStr += size.Width + "x" + size.Height + (it.hasNext() ? ", " : "");
                int dist = System.Math.Abs(quality.resX - size.Width);
                if (dist < minDist)
                {
                    minDist = dist;
                    v.resX  = size.Width;
                    v.resY  = size.Height;
                }
            }
            //Log.v(TAG, supportedSizesStr);
            if (quality.resX != v.resX || quality.resY != v.resY)
            {
                //  Log.v(TAG, "Resolution modified: " + quality.resX + "x" + quality.resY + "->" + v.resX + "x" + v.resY);
            }

            return(v);
        }
Ejemplo n.º 6
0
        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);
            }
        }
Ejemplo n.º 7
0
        public Size FindBestPreviewSize(Android.Hardware.Camera.Parameters p, Size screenRes)
        {
            var max = p.SupportedPreviewSizes.Count;

            var s = p.SupportedPreviewSizes[max - 1];

            return(new Size(s.Width, s.Height));
        }
Ejemplo n.º 8
0
        private void SetFlashModeOff(Android.Hardware.Camera.Parameters oldParameters)
        {
            IList <string> supportedFlashModes = oldParameters.SupportedFlashModes;

            if (supportedFlashModes != null &&
                supportedFlashModes.Contains(Android.Hardware.Camera.Parameters.FlashModeOff))
            {
                oldParameters.FlashMode = Android.Hardware.Camera.Parameters.FlashModeOff;
            }
        }
Ejemplo n.º 9
0
        public void SetFocusModeOn(Android.Hardware.Camera.Parameters oldParameters)
        {
            IList <string> supportedFocusModes = oldParameters.SupportedFocusModes;

            if (supportedFocusModes != null &&
                supportedFocusModes.Contains(Android.Hardware.Camera.Parameters.FocusModeContinuousVideo))
            {
                oldParameters.FocusMode = Android.Hardware.Camera.Parameters.FocusModeContinuousVideo;
            }
        }
Ejemplo n.º 10
0
        public void SetWhiteBalanceAuto(Android.Hardware.Camera.Parameters oldParameters)
        {
            IList <string> supportedWhiteBalance = oldParameters.SupportedWhiteBalance;

            if (supportedWhiteBalance != null &&
                supportedWhiteBalance.Contains(Android.Hardware.Camera.Parameters.WhiteBalanceAuto))
            {
                oldParameters.WhiteBalance = Android.Hardware.Camera.Parameters.WhiteBalanceAuto;
            }
        }
Ejemplo n.º 11
0
        public void SetSceneModeAuto(Android.Hardware.Camera.Parameters oldParameters)
        {
            IList <string> supportedSceneModes = oldParameters.SupportedSceneModes;

            if (supportedSceneModes != null &&
                supportedSceneModes.Contains(Android.Hardware.Camera.Parameters.SceneModeAuto))
            {
                oldParameters.SceneMode = Android.Hardware.Camera.Parameters.SceneModeAuto;
            }
        }
Ejemplo n.º 12
0
        public CameraPreview(Context context, Android.Hardware.Camera camera) : base(context)
        {
            cameraInstance = camera;
            this.context   = context;
            surfaceHolder  = Holder;
            surfaceHolder.AddCallback(this);

            Android.Hardware.Camera.Parameters parameters = cameraInstance.GetParameters();
            parameters.FocusMode = Android.Hardware.Camera.Parameters.FocusModeAuto;
            cameraInstance.SetParameters(parameters);
        }
Ejemplo n.º 13
0
        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;
            }
        }
Ejemplo n.º 14
0
        private void OpenCamera()
        {
            if (CheckSelfPermission(Manifest.Permission.Camera) != Permission.Granted)
            {
                RequestCameraPermission();
                return;
            }


            camera = Android.Hardware.Camera.Open();
            Android.Hardware.Camera.Parameters parameters = camera.GetParameters();
            parameters.PictureFormat = ImageFormatType.Jpeg;
            parameters.PreviewFormat = ImageFormatType.Nv21;
            if (parameters.SupportedFocusModes.Contains(Android.Hardware.Camera.Parameters.FocusModeContinuousVideo))
            {
                parameters.FocusMode = Android.Hardware.Camera.Parameters.FocusModeContinuousVideo;
            }
            IList <Android.Hardware.Camera.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);
        }
Ejemplo n.º 15
0
        private void StartCamera()
        {
            holder = view.Holder;
            holder.AddCallback(this);

            camera = Android.Hardware.Camera.Open(1);
            Android.Hardware.Camera.Parameters p = camera.GetParameters();
            p.SetPreviewSize(320, 240);

            camera.SetDisplayOrientation(90);
            camera.SetParameters(p);
            camera.SetPreviewCallback(this);
        }
Ejemplo n.º 16
0
 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 SurfaceChanged(ISurfaceHolder arg0, Android.Graphics.Format arg1, int arg2, int arg3)
        {
            //get camera parameters
            parameters = mCamera.GetParameters();

            //set camera parameters
            mCamera.SetParameters(parameters);

            //mCamera.SetDisplayOrientation (90);
            mCamera.StartPreview();

            //Take the picture
            mCamera.TakePicture(null, null, this);
            //Log.Debug ("","picture taken!!!");
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Take a picture
        /// </summary>
        /// <param name="callback"></param>
        public void TakePicture(Action <string> callback)
        {
            if (_camera == null)
            {
                return;
            }

            _callback = callback;

            Android.Hardware.Camera.Parameters p = _camera.GetParameters();
            p.PictureFormat = Android.Graphics.ImageFormatType.Jpeg;
            //var size = p.PreviewSize;
            _camera.SetParameters(p);
            _camera.TakePicture(this, this, this);
        }
Ejemplo n.º 19
0
        public List <CameraPixels> GetCameraResolution()
        {
            List <CameraPixels> camPixels = new List <CameraPixels>();

            if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
            {
                //Lolipop and above
                CameraManager          camMan  = (CameraManager)mactivity.GetSystemService(Context.CameraService);
                string[]               camId   = camMan.GetCameraIdList();
                CameraCharacteristics  camChar = camMan.GetCameraCharacteristics(camId[0]); //0 - mostly for back cam
                StreamConfigurationMap camMap  = (StreamConfigurationMap)camChar.Get(CameraCharacteristics.ScalerStreamConfigurationMap);
                Android.Util.Size[]    sizes   = camMap.GetOutputSizes((int)ImageFormatType.Jpeg);

                System.Diagnostics.Debug.WriteLine($"Camera sizes: {sizes.Length}");

                foreach (var size in sizes)
                {
                    //System.Diagnostics.Debug.WriteLine($"Sizes: {size.Width} x {size.Height} = {Convert.ToDouble(size.Width) * Convert.ToDouble(size.Height) / Convert.ToDouble(1024000)} megs");
                    camPixels.Add(new CameraPixels()
                    {
                        Height     = size.Height,
                        Width      = size.Width,
                        Megapixels = Math.Round(Convert.ToDecimal(size.Width) * Convert.ToDecimal(size.Height) / Convert.ToDecimal(1000000), 1)
                    });
                }
            }
            else
            {
                //pre-lolipop
                Android.Hardware.Camera              cam      = Android.Hardware.Camera.Open();
                Android.Hardware.Camera.Parameters   camParam = cam.GetParameters();
                IList <Android.Hardware.Camera.Size> plSizes  = camParam.SupportedPictureSizes;

                foreach (var size in plSizes)
                {
                    System.Diagnostics.Debug.WriteLine($"Sizes: {size.Width} x {size.Height} = {Convert.ToDouble(size.Width) * Convert.ToDouble(size.Height) / Convert.ToDouble(1024000)} megs");
                    camPixels.Add(new CameraPixels()
                    {
                        Height     = size.Height,
                        Width      = size.Width,
                        Megapixels = Math.Round(Convert.ToDecimal(size.Width) * Convert.ToDecimal(size.Height) / Convert.ToDecimal(1000000), 1)
                    });
                }
                cam.Release();
            }

            return(camPixels);
        }
Ejemplo n.º 20
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            Window.RequestFeature(WindowFeatures.NoTitle);
            Window.AddFlags(WindowManagerFlags.Fullscreen | WindowManagerFlags.TurnScreenOn);

            SetContentView(Resource.Layout.RecordWordView);

            _surfaceView   = FindViewById <SurfaceView>(Resource.Id.surfaceView);
            _camera        = GetCameraInstance();
            _surfaceHolder = _surfaceView.Holder;
            _surfaceHolder.AddCallback(this);
            _parameters = _camera.GetParameters();
            StartCamera();
        }
Ejemplo n.º 21
0
 public static Bitmap convertYuvByteArrayToBitmap(byte[] data, Android.Hardware.Camera camera)
 {
     try
     {
         Android.Hardware.Camera.Parameters parameters = camera.GetParameters();
         Android.Hardware.Camera.Size       size       = parameters.PreviewSize;
         YuvImage image = new YuvImage(data, parameters.PreviewFormat, size.Width, size.Height, null);
         System.IO.MemoryStream out_ = new System.IO.MemoryStream();
         image.CompressToJpeg(new Rect(0, 0, size.Width, size.Height), int.Parse(MainValues.quality), out_);
         byte[] imageBytes = out_.ToArray();
         out_.Flush(); out_.Close(); out_.Dispose();
         return(BitmapFactory.DecodeByteArray(imageBytes, 0, imageBytes.Length));
     }
     catch (Exception)
     {
         return(null);
     }
 }
Ejemplo n.º 22
0
        public void SurfaceCreated(ISurfaceHolder holder)
        {
            // TODO Auto-generated method stub
            try
            {
                camera = Android.Hardware.Camera.Open();
                Android.Hardware.Camera.Parameters param = camera.GetParameters();

                // Check what resolutions are supported by your camera
                IList <Android.Hardware.Camera.Size> sizes = param.SupportedPictureSizes;

                // setting small image size in order to avoid OOM error
                Android.Hardware.Camera.Size cameraSize = null;
                foreach (Android.Hardware.Camera.Size size in sizes)
                {
                    //set whatever size you need
                    //if(size.height<500) {
                    cameraSize = size;
                    break;
                    //}
                }

                if (cameraSize != null)
                {
                    param.SetPictureSize(cameraSize.Width, cameraSize.Height);
                    camera.SetParameters(param);

                    float ratio = relativeLayout.Height * 1f / cameraSize.Height;
                    float w     = cameraSize.Width * ratio;
                    float h     = cameraSize.Height * ratio;
                    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams((int)w, (int)h);
                    cameraSurfaceView.LayoutParameters = (lp);
                }
            }
            catch (RuntimeException e)
            {
                Toast.MakeText(
                    ApplicationContext,
                    "Device camera  is not working properly, please try after sometime.",
                    ToastLength.Long).Show();
            }
        }
Ejemplo n.º 23
0
 private Bitmap convertYuvByteArrayToBitmap(byte[] data, Android.Hardware.Camera camera)
 {
     try
     {
         Android.Hardware.Camera.Parameters parameters = camera.GetParameters();
         Android.Hardware.Camera.Size       size       = parameters.PreviewSize;
         using (YuvImage image = new YuvImage(data, parameters.PreviewFormat, size.Width, size.Height, null))
         {
             using (MemoryStream memoryStream = new MemoryStream())
             {
                 image.CompressToJpeg(new Rect(0, 0, size.Width, size.Height), int.Parse(MainValues.quality), memoryStream);
                 return(BitmapFactory.DecodeByteArray(memoryStream.ToArray(), 0, memoryStream.ToArray().Length));
             }
         }
     }
     catch (Exception)
     {
         return(null);
     }
 }
Ejemplo n.º 24
0
        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);
        }
Ejemplo n.º 25
0
 private void opPreviewSize(int width, int height)
 {
     if (camera != null && width > 0)
     {
         try
         {
             Android.Hardware.Camera.Parameters parameters = camera.GetParameters();
             Android.Hardware.Camera.Size       optSize    = getOptimalSize(width, height, new List <Android.Hardware.Camera.Size>(camera.GetParameters().SupportedPreviewSizes));
             Log.Info("wtf", "opPreviewSize-> " + optSize.Width + " " + optSize.Height);
             parameters.SetPreviewSize(optSize.Width, optSize.Height);
             // parameters.setPreviewFpsRange(10, 15);
             camera.SetParameters(parameters);
             camera.StartPreview();
         }
         catch (RuntimeException e)
         {
             e.PrintStackTrace();
         }
     }
 }
Ejemplo n.º 26
0
        public static int[] determineMaximumSupportedFramerate(Android.Hardware.Camera.Parameters parameters parameters)
        {
            int[]         maxFps = new int[] { 0, 0 };
            System.String supportedFpsRangesStr = "Supported frame rates: ";
            IList <int[]> supportedFpsRanges    = parameters.SupportedPreviewFpsRange;

            //for (Iterator<int[]> it = supportedFpsRanges.iterator(); it.hasNext();)
            foreach (int[] it in supportedFpsRanges)
            {
                int[] interval = it;
                // Intervals are returned as integers, for example "29970" means "29.970" FPS.
                //supportedFpsRangesStr += interval[0] / 1000 + "-" + interval[1] / 1000 + "fps" + (it.hasNext() ? ", " : "");
                if (interval[1] > maxFps[1] || (interval[0] > maxFps[0] && interval[1] == maxFps[1]))
                {
                    maxFps = interval;
                }
            }
            //   Log.v(TAG, supportedFpsRangesStr);
            return(maxFps);
        }
Ejemplo n.º 27
0
        //初始化相机
        private void initCamera()
        {
            mCamera.StopPreview();
            if (null != mCamera)
            {
                Android.Hardware.Camera.Parameters myParam = mCamera.GetParameters();

                //设置大小和方向等参数
                myParam.SetPreviewSize(1280, 720);
                myParam.SetPictureSize(640, 480);
                myParam.SetRotation(90);
                myParam.Set("iso", 100);
                myParam.Set("jpeg-quality", 100);
                myParam.Zoom = 14;
                mCamera.SetDisplayOrientation(90);
                mCamera.SetParameters(myParam);
                mCamera.StartPreview();
                //mCamera.SetPreviewCallback (this);
            }
        }
Ejemplo n.º 28
0
        public void SurfaceChanged(ISurfaceHolder holder, global::Android.Graphics.Format format, int w, int h)
        {
            if (camera == null)
            {
                return;
            }

            Android.Hardware.Camera.Parameters parameters = camera.GetParameters();

            width  = parameters.PreviewSize.Width;
            height = parameters.PreviewSize.Height;

            camera.SetParameters(parameters);
            camera.SetDisplayOrientation(90);
            camera.StartPreview();

            cameraResolution = new Size(parameters.PreviewSize.Width, parameters.PreviewSize.Height);

            AutoFocus();
        }
Ejemplo n.º 29
0
        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;
            }
        }
Ejemplo n.º 30
0
        public static Android.Hardware.Camera.Size GetPictureSize(this Android.Hardware.Camera.Parameters p, int w)
        {
            var sizes  = p.SupportedPictureSizes;
            var sizes2 = p.SupportedPreviewSizes;
            var offset = Integer.MaxValue;

            Android.Hardware.Camera.Size rs = null;

            if (sizes != null)
            {
                foreach (var size in sizes)
                {
                    foreach (var size2 in sizes2)
                    {
                        if (size.Width == size2.Width && size.Height == size2.Height)
                        {
                            int curSize = 0;

                            if (size.Width > size.Height)
                            {
                                curSize = size.Width;
                            }
                            else
                            {
                                curSize = size.Height;
                            }

                            if (size.Width >= w && size.Height >= w && (curSize - w) < offset)
                            {
                                offset = curSize - w;
                                rs     = size;
                            }
                        }
                    }
                }
            }

            return(rs);
        }
Ejemplo n.º 31
0
		// getting camera parameters
		private void GetCamera() {
			if (camera == null) {
				try {
					camera = Android.Hardware.Camera.Open();
					params1 = camera.GetParameters();
				} catch (Exception e) {
					Log.Error("Camera Error. Failed to Open. Error: ", e.Message);
				}
			}
		}
Ejemplo n.º 32
0
		/*
 * Turning On flash
 */
		private void TurnOnFlash() {
			//isFlashOn = true;
			if (!isFlashOn) {
				if (camera == null) {
					return;
				}
				// play sound
				//playSound();

				params1 = camera.GetParameters ();
				params1.FlashMode= Android.Hardware.Camera.Parameters.FlashModeTorch;
				camera.SetParameters(params1);
				camera.StartPreview ();
				isFlashOn = true;

				// changing button/switch image
				//toggleButtonImage();
			}

		}
Ejemplo n.º 33
0
		/*
		 * Turning Off flash
 	*/
		private void TurnOffFlash() {
			if (isFlashOn) {
				if (camera == null) {
					return;
				}
				// play sound
				//playSound();

				params1 = camera.GetParameters ();
				params1.FlashMode= Android.Hardware.Camera.Parameters.FlashModeOn;
				camera.SetParameters(params1);
				camera.StopPreview();
				isFlashOn = false;

				// changing button/switch image
				//toggleButtonImage();
			}
		}