Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImageCropper.Forms: How to remove the multiple pop-up? #44

Open
sreejithsree139 opened this issue Jan 21, 2021 · 1 comment
Open

ImageCropper.Forms: How to remove the multiple pop-up? #44

sreejithsree139 opened this issue Jan 21, 2021 · 1 comment

Comments

@sreejithsree139
Copy link

I am using ImageCropper.Forms for cropping the image selected from the camera and gallery. I have 3 options for changing a profile picture; Take Photo, Upload from Gallery and Select Avatar. So for showing the Media options I am using a DisplayActionSheet like below:

var actionSheet = await DisplayActionSheet(null,"Cancel", null, "Take Photo", "Upload from Gallery", "Select Avatar");
if (actionSheet == "Take Photo")
{
	OpenCamera();
}
else if(actionSheet == "Upload from Gallery")
{
	Opengallery();
}
else if(actionSheet == "Select Avatar")
{
	OpenAvatar();
}

OpenCamera() and Opengallery() are added below. That code is also asking the Take Photo and Photo Library options again as a popup. I don't need that pop up, is there any way to remove the second popup asked by ImageCropper.Forms and load the camera or gallery directly?

My Code:

    async void OpenCamera()
	{
		try
		{
			await CrossMedia.Current.Initialize();
            //I need to open camera only here, no need of a pop up again.
			new ImageCropper()
			{
				PageTitle = "Test Title",
				AspectRatioX = 1,
				AspectRatioY = 1,
				CropShape = ImageCropper.CropShapeType.Rectangle,
				SelectSourceTitle = "Select source",
				TakePhotoTitle = "Take Photo",
				PhotoLibraryTitle = "Photo Library",
				Success = (imageFile) =>
				{
					Device.BeginInvokeOnMainThread(() =>
					{
						profilephoto.Source = ImageSource.FromFile(imageFile);
					});
				}
			}.Show(this);
		}
		catch (Exception ex)
		{
			System.Diagnostics.Debug.WriteLine("CameraException:>" + ex);
		}
	}

async void Opengallery()
{
	try
	{
		await CrossMedia.Current.Initialize();
        //I need to open gallery only here, no need of a pop up again.
		new ImageCropper()
		{
			PageTitle = "Test Title",
			AspectRatioX = 1,
			AspectRatioY = 1,
			CropShape = ImageCropper.CropShapeType.Rectangle,
			SelectSourceTitle = "Select source",
			TakePhotoTitle = "Take Photo",
			PhotoLibraryTitle = "Photo Library",
			Success = (imageFile) =>
			{
				Device.BeginInvokeOnMainThread(() =>
				{
					profilephoto.Source = ImageSource.FromFile(imageFile);
					//var stream = ImageSource.FromFile(imageFile);
					//imagefile = imageFile;
				});
			}
		}.Show(this);
	}
}

Screenshot: https://i.stack.imgur.com/qYBuu.jpg

Is there any way to separate camera and gallery code like MediaPlugin?

@jpacov
Copy link

jpacov commented Jan 21, 2021

You can pass an image to the Show method and it will not prompt the user with the popup. Refer to the readme

Show​(​this​, ​imageFileName​);

And you can previously use Media.Plugin by your own to get the image directly from the source you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants