Skip to content

Instantly share code, notes, and snippets.

@FrayxRulez
Last active July 5, 2017 16:18
Show Gist options
  • Save FrayxRulez/c2f1bbfa996ad5751b87 to your computer and use it in GitHub Desktop.
Save FrayxRulez/c2f1bbfa996ad5751b87 to your computer and use it in GitHub Desktop.
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
Copy link

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
Copy link

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

@dekenless
Copy link

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
Copy link

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
Copy link

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