-
May 30th, 2019, 04:09 PM
#1
Thread Starter
Fanatic Member
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
-
Apr 6th, 2020, 12:40 AM
#2
Member
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.
-
Apr 6th, 2020, 12:41 AM
#3
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|