Exemplo n.º 1
0
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        SetContentView(Resource.Layout.activity_camera);
        // Create your application here
        image = FindViewById<ImageView>(Resource.Id.imageView_Photo);
        fotoButton = FindViewById<ImageView>(Resource.Id.imageView_foto);
        preview = FindViewById<SurfaceView>(Resource.Id.surfaceView_Photo);


        /*image.DrawingCacheEnabled = true;
        image.Measure(MeasureSpec.MakeMeasureSpec(200, MeasureSpecMode.Exactly),
                        MeasureSpec.MakeMeasureSpec(200, MeasureSpecMode.Exactly));
        image.Layout(0, 0, image.MeasuredWidth, image.MeasuredHeight);
        image.BuildDrawingCache(true);
        Bitmap layoutBitmap = Bitmap.CreateBitmap(image.DrawingCache);
        image.DrawingCacheEnabled = false;*/

        fotoButton.SetOnClickListener(new OnClickListener()
        {
            Parent = this
        });

        previewHolder = preview.Holder;
        previewHolder.AddCallback(
            new SurfaceCalback()
            {
                Parent = this
            });

        previewHolder.SetType(SurfaceType.PushBuffers);

        previewHolder.SetFixedSize(Window.WindowManager.DefaultDisplay.Width,
                                   Window.WindowManager.DefaultDisplay.Height);
    }
Exemplo n.º 2
0
        public void SurfaceCreated(ISurfaceHolder holder)
        {
            try
            {
                if (!(Context.GetSystemService(Class.FromType(typeof(CameraManager))) is CameraManager manager))
                {
                    return;
                }

                string frontCameraId = manager.GetCameraIdList().FirstOrDefault(id => IsFrontFacingCamera(manager, id));
                CameraCharacteristics frontCamera = manager.GetCameraCharacteristics(frontCameraId);

                if (!(frontCamera?.Get(CameraCharacteristics.ScalerStreamConfigurationMap) is StreamConfigurationMap map))
                {
                    return;
                }

                Size[] outputSizes = map.GetOutputSizes(Class.FromType(holder.GetType()));
                Size   firstSmall  = outputSizes
                                     .Where(size => (double)size.Width / size.Height == 16d / 9)
                                     .First(size => size.Height < 900 && size.Width < 900);

                holder.SetFixedSize(firstSmall.Width, firstSmall.Height);

                CameraDevice.StateCallback stateCallback = new MyCameraCallback(holder.Surface, Element);
                manager.OpenCamera(frontCameraId, stateCallback, new Handler(msg => { }));
            }
            catch (Java.IO.IOException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Exemplo n.º 3
0
        public void StartVideoPlayback(SurfaceView surface, string FilePath)
        {
            if (_player != null)
            {
                StopVideoPlayback();
            }
            _player = new MediaPlayer();

            ISurfaceHolder holder = surface.Holder;

            holder.SetType(Android.Views.SurfaceType.PushBuffers);
            holder.SetFixedSize(400, 300);

            _player.SetDisplay(holder);
            _player.SetDataSource(FilePath);
            _player.Prepare();
            _player.Start();
        }
Exemplo n.º 4
0
 private void startVideoPlayback()
 {
     Log.Verbose(TAG, "startVideoPlayback");
     holder.SetFixedSize(mVideoWidth, mVideoHeight);
     mMediaPlayer.Start();
 }