Skip to content

Instantly share code, notes, and snippets.

@FrayxRulez FrayxRulez/CropImage.cs
Last active Jul 5, 2017

Embed
What would you like to do?
private async Task CropImage()
{
// Create destination file and obtain sharing token
var file = await ApplicationData.Current.LocalFolder.CreateFileAsync("Cropped.jpg", CreationCollisionOption.ReplaceExisting);
var token = SharedStorageAccessManager.AddFile(file);
// Specify the app to launch using LaunchUriForResults
var options = new LauncherOptions();
options.TargetApplicationPackageFamilyName = "Microsoft.Windows.Photos_8wekyb3d8bbwe";
// Specify all the parameters
var parameters = new ValueSet();
parameters.Add("CropWidthPixels", 500);
parameters.Add("CropHeightPixels", 500);
parameters.Add("EllipticalCrop", true);
parameters.Add("ShowCamera", false);
parameters.Add("DestinationToken", token);
// Launches the app and wait for results
var result = await Launcher.LaunchUriForResultsAsync(new Uri("microsoft.windows.photos.crop:"), options, parameters);
// Check if the user has really cropped the picture
if (result.Status == LaunchUriStatus.Success && result.Result != null)
{
// Loads the picture
var stream = await file.OpenReadAsync();
var bitmap = new BitmapImage();
await bitmap.SetSourceAsync(stream);
// Set the picture as Source of an Image control
Preview.Source = bitmap;
}
}
@Matti-Koopa

This comment has been minimized.

Copy link

Matti-Koopa commented Jun 23, 2016

Here is how to do this with your own image directly (versus letting the user pick one in the Image Gallery). Just add the token as an input parameter as well (and write something to file before, of course):
parameters.Add("InputToken", token);

@sonnemaf

This comment has been minimized.

Copy link

sonnemaf commented Feb 24, 2017

I noticed that CropWidthPixels and CropHeightPixels don't work on Desktop. It only works on Mobile. Will this be fixed?

@dekenless

This comment has been minimized.

Copy link

dekenless commented Apr 30, 2017

I noticed that CropWidthPixels and CropHeightPixels are not consistently respected, it worked on Desktop for me with Photo App version16.511.8780.0, but not in 17.313.10010.0

@bengawin

This comment has been minimized.

Copy link

bengawin commented May 31, 2017

Thanks! Just what I was looking for.
But I can't take pictures in portrait, the app flips them heads to bottom.
I have noticed the issue repeats itself in the people app.

@lancecontreras

This comment has been minimized.

Copy link

lancecontreras commented Jul 5, 2017

I would also like to us LaunchUriForResultsAsync to launch my other app. My problem is that it only launches another app in 500x500 window size. I need something bigger than that. Is it possible to make it full screen or maybe any size bigger than 500?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.