Example #1
0
        public void SavePictureFile(string filename_, Media.Plugin.Abstractions.MediaFile file)
        {
            Stream stream = file.GetStream();

            var path     = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            var filename = System.IO.Path.Combine(path, filename_);

            using (var fileStream = System.IO.File.Create(filename)) {
                stream.Seek(0, SeekOrigin.Begin);
                stream.CopyTo(fileStream);
                fileStream.Close();

                stream.Dispose();
                fileStream.Dispose();
                GC.Collect();
            }
        }
Example #2
0
        protected async void PickPhotoFromGallery()
        {
            try
            {
                //aciona a escolha da foto via plugin
                Media.Plugin.Abstractions.MediaFile photo = await CrossMedia.Current.PickPhotoAsync();

                //se o retorno não for "nulo", ou seja o usuário cancelou a operação, então pega o nome da foto escolhida
                if (photo != null)
                {
                    Sessao.OcorrenciaAtiva.CaminhoImage = photo.Path;
                    Sessao.OcorrenciaAtiva.NomeImagem   = photo.Path.Substring(photo.Path.LastIndexOf("/") + 1, photo.Path.Length - photo.Path.LastIndexOf("/") - 1);
                    Sessao.OcorrenciaAtiva.Image        = photo;
                    ApplyPhoto();
                }
            }
            catch (Exception ex)
            {
                DisplayLog(string.Format("{0} : {1}", "PickPhotoFromGallery", ex.Message));
            }
        }
Example #3
0
        protected void AtribuiEventoCapturaFotos()
        {
            try
            {
                //evento para capturar foto
                var tapGestureRecognizerSnapShot = new TapGestureRecognizer();

                //se o dispositivo não possuir camera, desabilita o clique de chamada da opção de foto e
                //informa os procedimentos ao usuario quanto a carga de fotos local (galeria)

                //não possui camera?
                if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
                {
                    //não, então testa se as fotos estão liberadas para serem escolhidas no aparelho pode escolher fotos?
                    if (!CrossMedia.Current.IsPickPhotoSupported)
                    {
                        //não, não pode escolher
                        btSnapshot.Source        = "ic_picture_blocked.png";
                        lblSnapshotGuidance.Text = "NÃO É POSSÍVEL INCLUIR UMA FOTO. MESMO ASSIM VOCÊ PODE CONTINUAR A PUBLICAÇÃO DA SUA OCORRÊNCIA.";
                    }
                    else
                    {
                        //sim, pode escolher
                        btSnapshot.Source        = "ic_picture_gallery.png";
                        lblSnapshotGuidance.Text = "CLIQUE NO ÍCONE AO LADO PARA ESCOLHER UMA FOTO EM SEU DISPOSITIVO.";

                        //ao clicar executa o evento
                        tapGestureRecognizerSnapShot.Tapped += (object sender, EventArgs e) => {
                            PickPhotoFromGallery();
                        };

                        //adiciona evento a imagem
                        btSnapshot.GestureRecognizers.Add(tapGestureRecognizerSnapShot);
                    }
                }
                else
                {
                    //possui camera
                    tapGestureRecognizerSnapShot.Tapped += async(object sender, EventArgs e) => {
                        //variavel para retenção da resposta
                        string result = string.Empty;

                        // é permitido escolher foto na galeria também?
                        if (CrossMedia.Current.IsPickPhotoSupported)
                        {
                            //sim, pode escolher, então mostra um pop up com as opções para captura de foto
                            result = await DisplayActionSheet("TaVazando - Foto", "Fechar", "", new string[] { "Nova Foto", "Escolher na Galeria" });
                        }
                        else
                        {
                            //não, não pode
                            result = "nova foto";
                        }

                        //testa resultado
                        if (!string.IsNullOrEmpty(result) && result.ToLower().Equals("nova foto"))
                        {
                            //cria objeto de midia
                            Media.Plugin.Abstractions.StoreCameraMediaOptions options = new Media.Plugin.Abstractions.StoreCameraMediaOptions();

                            //cria novo nome para a imagem utilizando os 10 primeiros digitos de um novo Guid
                            options.Name = string.Format("ocr_{0}", Guid.NewGuid().ToString().Substring(0, 10));

                            //ativa a camera
                            Media.Plugin.Abstractions.MediaFile photo = await CrossMedia.Current.TakePhotoAsync(options);

                            Sessao.OcorrenciaAtiva.CaminhoImage = photo.Path;
                            Sessao.OcorrenciaAtiva.NomeImagem   = options.Name;
                            Sessao.OcorrenciaAtiva.Image        = photo;
                            ApplyPhoto();
                        }
                        else
                        {
                            //escolhe foto diretamente do celular
                            PickPhotoFromGallery();
                        }
                    };

                    btSnapshot.GestureRecognizers.Add(tapGestureRecognizerSnapShot);
                }
            }
            catch (Exception ex)
            {
                DisplayLog(ex.Message);
                DisplayLog(string.Format("{0} : {1}", "AtribuiEventoCapturaFotos", ex.Message));
            }
        }