Results 1 to 3 of 3

Thread: After photo gallery browsing it goes back to the first page

  1. #1

    Thread Starter
    Fanatic Member vuyiswamb's Avatar
    Join Date
    Jan 2007
    Location
    South Africa
    Posts
    829

    After photo gallery browsing it goes back to the first page

    Good Day

    in my Xamarin page i have a button that browse the gallery to allow a user to bind it to an image editor , after selecting the image , the page refreshes to the first page that led to this current page. i would like to make it keep it in the current page after image selection . below is the code on my button

    Code:
    async private void Btnupload_Clicked(object sender, EventArgs e)
            {
                GenericMethods.IS_IMAGE_SELECTON = true;
                    if (!CrossMedia.Current.IsPickPhotoSupported)
                    {
                        await DisplayAlert("Photos Not Supported", ":( Permission not granted to photos.", "OK");
                        return;
                    }
                    var file = await CrossMedia.Current.PickPhotoAsync(new Plugin.Media.Abstractions.PickMediaOptions
                    {
                        PhotoSize = Plugin.Media.Abstractions.PhotoSize.Medium
                    });
    
                    if (file == null)
                        return;
    
                    filePath = file.Path;
                    paths.Enqueue(filePath);
    
                    //Linux path 
                    readytosave = GenericMethods.StreamToByteArray(file.GetStream());
    
                    Uri uri = new Uri(file.Path);
                    filename = string.Empty;
                    if (uri.IsFile)
                    {
                        filename = System.IO.Path.GetFileName(uri.LocalPath);
                    }
                    var extension = filename.Split('.')[1].ToLower();
    
                    file_extension = extension;
    
                     imageEditor.Source = ImageSource.FromStream(() =>
                    {
                        var stream = file.GetStream();
                        return stream;
                    });
                imagepopup.IsOpen = true;
            }
    Thanks

  2. #2

    Re: After photo gallery browsing it goes back to the first page

    Display an ActionSheet with Prism.IPageDialogService to give choices to the user.

    Method for a button.

    Code:
    private async void AddImage() // This is your method for your button
    {
        string chosen = await _dialogService.DisplayActionSheetAsync("Which source do you want to use?", "Cancel", null, "Camera", "Galery");
        if (chosen == "Camera")
        {
            TakePhoto();
        }
        else if (chosen == "Galery")
        {
            PickPhoto();
        }
    }
    Implementation of TakePhoto()

    Code:
    private async void TakePhoto()
    {
        await CrossMedia.Current.Initialize();
    
        if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
        {
            await _dialogService.DisplayAlertAsync("Warning", "Camera not available", "OK");
            return;
        }
    
        _mediaFile = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
        {
            SaveToAlbum = true,
            Directory = "Sample",
            Name = "sample" + DateTime.Now.ToLocalTime().ToString("yyyyMMddHHmmss") + ".jpg"
        });
    
        if (_mediaFile == null)
        {
            return;
        }
    
        ImageButtonAddGroup = _mediaFile.Path;
    }
    Implementation of PickPhoto()

    Code:
    private async void PickPhoto()
    {
        await CrossMedia.Current.Initialize();
    
        if (!CrossMedia.Current.IsPickPhotoSupported)
        {
            await _dialogService.DisplayAlertAsync("Warning", "Camera not available", "OK");
            return;
        }
    
        _mediaFile = await CrossMedia.Current.PickPhotoAsync();
        if (_mediaFile == null)
        {
            return;
        }
        ImageButtonAddGroup = _mediaFile.Path;
    }
    Using this code you can select a pic from gallery and take a pic from camera.

  3. #3

    Re: After photo gallery browsing it goes back to the first page

    Display an ActionSheet with Prism.IPageDialogService to give choices to the user.

    Method for a button.

    Code:
    private async void AddImage() // This is your method for your button
    {
        string chosen = await _dialogService.DisplayActionSheetAsync("Which source do you want to use?", "Cancel", null, "Camera", "Galery");
        if (chosen == "Camera")
        {
            TakePhoto();
        }
        else if (chosen == "Galery")
        {
            PickPhoto();
        }
    }
    Implementation of TakePhoto()

    Code:
    private async void TakePhoto()
    {
        await CrossMedia.Current.Initialize();
    
        if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
        {
            await _dialogService.DisplayAlertAsync("Warning", "Camera not available", "OK");
            return;
        }
    
        _mediaFile = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
        {
            SaveToAlbum = true,
            Directory = "Sample",
            Name = "sample" + DateTime.Now.ToLocalTime().ToString("yyyyMMddHHmmss") + ".jpg"
        });
    
        if (_mediaFile == null)
        {
            return;
        }
    
        ImageButtonAddGroup = _mediaFile.Path;
    }
    Implementation of PickPhoto()

    Code:
    private async void PickPhoto()
    {
        await CrossMedia.Current.Initialize();
    
        if (!CrossMedia.Current.IsPickPhotoSupported)
        {
            await _dialogService.DisplayAlertAsync("Warning", "Camera not available", "OK");
            return;
        }
    
        _mediaFile = await CrossMedia.Current.PickPhotoAsync();
        if (_mediaFile == null)
        {
            return;
        }
        ImageButtonAddGroup = _mediaFile.Path;
    }
    Using this code you can select a pic from gallery and take a pic from camera.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width