Пример #1
0
        private void SetEventHandlers()
        {
            _openCamera.Click += async(s, e) =>
            {
                try
                {
                    var size  = PhotoSize.Full;
                    var media = new Plugin.Media.MediaImplementation();
                    var file  = await Plugin.Media.CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
                    {
                        Directory     = "Sample",
                        Name          = $"{DateTime.Now}_{size}|\\?*<\":>/'.jpg".Replace(" ", string.Empty),
                        SaveToAlbum   = true,
                        PhotoSize     = PhotoSize.Full,
                        DefaultCamera = CameraDevice.Front
                    });

                    if (file == null)
                    {
                        return;
                    }
                    var path = file.Path;
                    Toast.MakeText(this, path, ToastLength.Long).Show();
                    System.Diagnostics.Debug.WriteLine(path);
                }
                catch (Exception ex)
                {
                    Toast.MakeText(this, ex.Message, ToastLength.Long).Show();
                }
            };
        }
Пример #2
0
        private async void PickVideo_ClickedAsync(object sender, System.EventArgs e)
        {
            var media = new Plugin.Media.MediaImplementation();
            var file  = await Plugin.Media.CrossMedia.Current.PickVideoAsync();

            if (file == null)
            {
                return;
            }
            var path = file.Path;
        }
Пример #3
0
        private async void TakeVideo_ClickedAsync(object sender, System.EventArgs e)
        {
            var media = new Plugin.Media.MediaImplementation();

            if (!media.IsCameraAvailable || !media.IsTakePhotoSupported)
            {
                throw new System.NotSupportedException();
            }
            var file = await Plugin.Media.CrossMedia.Current.TakeVideoAsync(new Plugin.Media.Abstractions.StoreVideoOptions
            {
                DefaultCamera = Plugin.Media.Abstractions.CameraDevice.Rear
            });

            var path = file.Path;
        }
        private async void TakeVideo_ClickedAsync(object sender, System.EventArgs e)
        {
            try {
                var media = new Plugin.Media.MediaImplementation();
                var file  = await Plugin.Media.CrossMedia.Current.TakeVideoAsync(new Plugin.Media.Abstractions.StoreVideoOptions
                {
                    DefaultCamera = Plugin.Media.Abstractions.CameraDevice.Rear
                });

                var path = file.Path;
                PostToastMessage(path);
            }
            catch (Exception ex)
            {
                PostToastMessage(ex.Message);
            }
        }
        private async void PickVideo_ClickedAsync(object sender, System.EventArgs e)
        {
            try {
                var media = new Plugin.Media.MediaImplementation();
                var file  = await Plugin.Media.CrossMedia.Current.PickVideoAsync();

                if (file == null)
                {
                    return;
                }
                var path = file.Path;
                PostToastMessage(path);
            }
            catch (Exception ex)
            {
                PostToastMessage(ex.Message);
            }
        }
Пример #6
0
        private async void PickPhoto_ClickedAsync(object sender, System.EventArgs e)
        {
            var media = new Plugin.Media.MediaImplementation();

            if (!media.IsCameraAvailable || !media.IsPickPhotoSupported)
            {
                throw new System.NotSupportedException();
            }
            var file = await Plugin.Media.CrossMedia.Current.PickPhotoAsync(new Plugin.Media.Abstractions.PickMediaOptions {
            });

            if (file == null)
            {
                return;
            }
            var path = file.Path;

            image.Load(path);
        }
Пример #7
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Manager.LocationUpdated += HandleLocationChanged;

            var info = CrossDeviceInfo.Current;

            DeviceName.Text    = info.DeviceName;
            DeviceVersion.Text = info.Model;
            DeviceOS.Text      = info.Platform + " " + info.Version;
            DeviceUID.Text     = info.Manufacturer;

            OpenCamera.TouchUpInside += async(s, e) =>
            {
                try
                {
                    var size  = PhotoSize.Full;
                    var media = new Plugin.Media.MediaImplementation();
                    var file  = await Plugin.Media.CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
                    {
                        Directory     = "Sample",
                        Name          = $"{DateTime.Now}_{size}|\\?*<\":>/'.jpg".Replace(" ", string.Empty),
                        SaveToAlbum   = true,
                        PhotoSize     = PhotoSize.Full,
                        DefaultCamera = CameraDevice.Front
                    });
                }
                catch (Exception ex)
                {
                    //Toast.MakeText(this, ex.Message, ToastLength.Long).Show();
                }
            };

            UIApplication.Notifications.ObserveDidEnterBackground((sender, args) => {
                Manager.LocationUpdated -= HandleLocationChanged;
            });

            UIApplication.Notifications.ObserveDidBecomeActive((sender, args) => {
                Manager.LocationUpdated += HandleLocationChanged;
            });
        }
Пример #8
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById <Button>(Resource.Id.MyButton);
            var    image  = FindViewById <ImageView>(Resource.Id.imageView1);

            var switchSize        = FindViewById <Switch>(Resource.Id.switch_size);
            var switchSaveToAlbum = FindViewById <Switch>(Resource.Id.switch_save_album);

            button.Click += async delegate
            {
                try
                {
                    var size  = switchSize.Checked ? Plugin.Media.Abstractions.PhotoSize.Medium : Plugin.Media.Abstractions.PhotoSize.Full;
                    var media = new Plugin.Media.MediaImplementation();
                    var file  = await Plugin.Media.CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
                    {
                        Directory     = "Sample",
                        Name          = $"{DateTime.Now}_{size}|\\?*<\":>/'.jpg".Replace(" ", string.Empty),
                        SaveToAlbum   = switchSaveToAlbum.Checked,
                        PhotoSize     = switchSize.Checked ? Plugin.Media.Abstractions.PhotoSize.Small : Plugin.Media.Abstractions.PhotoSize.Full,
                        DefaultCamera = Plugin.Media.Abstractions.CameraDevice.Front
                    });

                    if (file == null)
                    {
                        return;
                    }
                    var path = file.Path;
                    Toast.MakeText(this, path, ToastLength.Long).Show();
                    System.Diagnostics.Debug.WriteLine(path);

                    var bitmap = BitmapFactory.DecodeFile(file.Path);
                    image.SetImageBitmap(bitmap);
                    file.Dispose();
                }
                catch (Exception ex)
                {
                    Toast.MakeText(this, ex.Message, ToastLength.Long).Show();
                }
            };

            var pick = FindViewById <Button>(Resource.Id.button1);

            pick.Click += async(sender, args) =>
            {
                try
                {
                    var file = await Plugin.Media.CrossMedia.Current.PickPhotoAsync(new Plugin.Media.Abstractions.PickMediaOptions
                    {
                        PhotoSize = switchSize.Checked ? Plugin.Media.Abstractions.PhotoSize.Large : Plugin.Media.Abstractions.PhotoSize.Full
                    });

                    if (file == null)
                    {
                        return;
                    }
                    var path = file.Path;
                    Toast.MakeText(this, path, ToastLength.Long).Show();
                    System.Diagnostics.Debug.WriteLine(path);
                    var bitmap = BitmapFactory.DecodeFile(file.Path);
                    image.SetImageBitmap(bitmap);
                    file.Dispose();
                }
                catch (Exception ex)
                {
                    Toast.MakeText(this, ex.Message, ToastLength.Long).Show();
                }
            };

            FindViewById <Button>(Resource.Id.button2).Click += async(sender, args) =>
            {
                try
                {
                    var media = new Plugin.Media.MediaImplementation();
                    var file  = await Plugin.Media.CrossMedia.Current.TakeVideoAsync(new Plugin.Media.Abstractions.StoreVideoOptions
                    {
                        Directory   = "Sample",
                        Name        = "test.mp4",
                        SaveToAlbum = true
                    });

                    if (file == null)
                    {
                        return;
                    }
                    var path = file.Path;
                    System.Diagnostics.Debug.WriteLine(path);
                    Toast.MakeText(this, path, ToastLength.Long).Show();


                    file.Dispose();
                }
                catch (Exception ex)
                {
                    Toast.MakeText(this, ex.Message, ToastLength.Long).Show();
                }
            };


            FindViewById <Button>(Resource.Id.button3).Click += async(sender, args) =>
            {
                var media = new Plugin.Media.MediaImplementation();
                var file  = await Plugin.Media.CrossMedia.Current.PickVideoAsync();

                if (file == null)
                {
                    return;
                }

                var path = file.Path;
                Toast.MakeText(this, path, ToastLength.Long).Show();
                System.Diagnostics.Debug.WriteLine(path);

                file.Dispose();
            };
        }
Пример #9
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById <Button>(Resource.Id.MyButton);
            var    image  = FindViewById <ImageView>(Resource.Id.imageView1);

            button.Click += async delegate
            {
                var media = new Plugin.Media.MediaImplementation();
                var file  = await Plugin.Media.CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    Directory     = "Sample",
                    Name          = "test.jpg",
                    SaveToAlbum   = true,
                    DefaultCamera = Plugin.Media.Abstractions.CameraDevice.Front
                });

                if (file == null)
                {
                    return;
                }
                var path = file.Path;
                System.Diagnostics.Debug.WriteLine(path);

                image.SetImageBitmap(BitmapFactory.DecodeFile(file.Path));
                file.Dispose();
            };

            var pick = FindViewById <Button>(Resource.Id.button1);

            pick.Click += async(sender, args) =>
            {
                var file = await Plugin.Media.CrossMedia.Current.PickPhotoAsync();

                if (file == null)
                {
                    return;
                }
                var path = file.Path;
                System.Diagnostics.Debug.WriteLine(path);
                image.SetImageBitmap(BitmapFactory.DecodeFile(file.Path));
                file.Dispose();
            };

            FindViewById <Button>(Resource.Id.button2).Click += async(sender, args) =>
            {
                var media = new Plugin.Media.MediaImplementation();
                var file  = await Plugin.Media.CrossMedia.Current.TakeVideoAsync(new Plugin.Media.Abstractions.StoreVideoOptions
                {
                    Directory   = "Sample",
                    Name        = "test.jpg",
                    SaveToAlbum = true
                });

                if (file == null)
                {
                    return;
                }
                var path = file.Path;
                System.Diagnostics.Debug.WriteLine(path);



                file.Dispose();
            };


            FindViewById <Button>(Resource.Id.button3).Click += async(sender, args) =>
            {
                var media = new Plugin.Media.MediaImplementation();
                var file  = await Plugin.Media.CrossMedia.Current.PickVideoAsync();

                if (file == null)
                {
                    return;
                }

                var path = file.Path;
                System.Diagnostics.Debug.WriteLine(path);

                file.Dispose();
            };
        }
Пример #10
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById<Button>(Resource.Id.MyButton);
            var image = FindViewById<ImageView>(Resource.Id.imageView1);
            button.Click += async delegate
            {
                var media = new Plugin.Media.MediaImplementation();
                var file = await Plugin.Media.CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    Directory = "Sample",
                    Name = "test.jpg",
                    SaveToAlbum = true,
                    DefaultCamera = Plugin.Media.Abstractions.CameraDevice.Front
                });
                if (file == null)
                    return;
                var path = file.Path;
                System.Diagnostics.Debug.WriteLine(path);

                image.SetImageBitmap(BitmapFactory.DecodeFile(file.Path));
                file.Dispose();
            };

            var pick = FindViewById<Button>(Resource.Id.button1);
            pick.Click += async (sender, args) =>
              {
                  var file = await Plugin.Media.CrossMedia.Current.PickPhotoAsync();
                  if (file == null)
                      return;
                  var path = file.Path;
                  System.Diagnostics.Debug.WriteLine(path);
                  image.SetImageBitmap(BitmapFactory.DecodeFile(file.Path));
                  file.Dispose();
              };

            FindViewById<Button>(Resource.Id.button2).Click += async (sender, args) =>
              {
                  var media = new Plugin.Media.MediaImplementation();
                  var file = await Plugin.Media.CrossMedia.Current.TakeVideoAsync(new Plugin.Media.Abstractions.StoreVideoOptions
                  {
                      Directory = "Sample",
                      Name = "test.jpg",
                      SaveToAlbum = true
                  });
                  if (file == null)
                      return;
                  var path = file.Path;
                  System.Diagnostics.Debug.WriteLine(path);



                  file.Dispose();
                  
              };


            FindViewById<Button>(Resource.Id.button3).Click += async (sender, args) =>
            {
                var media = new Plugin.Media.MediaImplementation();
                var file = await Plugin.Media.CrossMedia.Current.PickVideoAsync();
                if (file == null)
                    return;

                var path = file.Path;
                System.Diagnostics.Debug.WriteLine(path);

                file.Dispose();
            };

        }