Task FinishVideoEditing(Action <PHContentEditingOutput> completionHandler) { PHContentEditingOutput contentEditingOutput = CreateOutput(); AVReaderWriter avReaderWriter = new AVReaderWriter(contentEditingInput.AvAsset, this); var tcs = new TaskCompletionSource <object> (); // Save filtered video avReaderWriter.WriteToUrl(contentEditingOutput.RenderedContentUrl, error => { bool success = error == null; PHContentEditingOutput output = success ? contentEditingOutput : null; if (!success) { Console.WriteLine("An error occured: {0}", error); } completionHandler(output); tcs.SetResult(null); // inform that we may safely clean up any data }); return(tcs.Task); }
Task FinishVideoEditing(Action<PHContentEditingOutput> completionHandler) { PHContentEditingOutput contentEditingOutput = CreateOutput (); AVReaderWriter avReaderWriter = new AVReaderWriter (contentEditingInput.AvAsset, this); var tcs = new TaskCompletionSource<object> (); // Save filtered video avReaderWriter.WriteToUrl (contentEditingOutput.RenderedContentUrl, error => { bool success = error == null; PHContentEditingOutput output = success ? contentEditingOutput : null; if(!success) Console.WriteLine ("An error occured: {0}", error); completionHandler (output); tcs.SetResult(null); // inform that we may safely clean up any data }); return tcs.Task; }
public void FinishContentEditing (Action<PHContentEditingOutput> completionHandler) { PHContentEditingOutput contentEditingOutput = new PHContentEditingOutput (contentEditingInput); // Adjustment data NSData archivedData = NSKeyedArchiver.ArchivedDataWithRootObject ((NSString)selectedFilterName); PHAdjustmentData adjustmentData = new PHAdjustmentData ("com.your-company.PhotoFilter", "1.0", archivedData); contentEditingOutput.AdjustmentData = adjustmentData; switch (contentEditingInput.MediaType) { case PHAssetMediaType.Image: { // Get full size image NSUrl url = contentEditingInput.FullSizeImageUrl; CIImageOrientation orientation = contentEditingInput.FullSizeImageOrientation; // Generate rendered JPEG data UIImage image = UIImage.FromFile (url.Path); image = TransformeImage (image, orientation); NSData renderedJPEGData = image.AsJPEG (0.9f); // Save JPEG data NSError error = null; bool success = renderedJPEGData.Save (contentEditingOutput.RenderedContentUrl, NSDataWritingOptions.Atomic, out error); if (success) { completionHandler (contentEditingOutput); } else { Console.WriteLine ("An error occured: {0}", error); completionHandler (null); } break; } case PHAssetMediaType.Video: { // Get AV asset AVReaderWriter avReaderWriter = new AVReaderWriter (contentEditingInput.AvAsset); avReaderWriter.Delegate = this; // Save filtered video avReaderWriter.WriteToUrl (contentEditingOutput.RenderedContentUrl, progress => { }, error => { if (error == null) { completionHandler (contentEditingOutput); return; } Console.WriteLine ("An error occured: {0}", error); completionHandler (null); }); break; } default: break; } }
public void FinishContentEditing(Action <PHContentEditingOutput> completionHandler) { PHContentEditingOutput contentEditingOutput = new PHContentEditingOutput(contentEditingInput); // Adjustment data NSData archivedData = NSKeyedArchiver.ArchivedDataWithRootObject((NSString)selectedFilterName); PHAdjustmentData adjustmentData = new PHAdjustmentData("com.your-company.PhotoFilter", "1.0", archivedData); contentEditingOutput.AdjustmentData = adjustmentData; switch (contentEditingInput.MediaType) { case PHAssetMediaType.Image: { // Get full size image NSUrl url = contentEditingInput.FullSizeImageUrl; CIImageOrientation orientation = contentEditingInput.FullSizeImageOrientation; // Generate rendered JPEG data UIImage image = UIImage.FromFile(url.Path); image = TransformeImage(image, orientation); NSData renderedJPEGData = image.AsJPEG(0.9f); // Save JPEG data NSError error = null; bool success = renderedJPEGData.Save(contentEditingOutput.RenderedContentUrl, NSDataWritingOptions.Atomic, out error); if (success) { completionHandler(contentEditingOutput); } else { Console.WriteLine("An error occured: {0}", error); completionHandler(null); } break; } case PHAssetMediaType.Video: { // Get AV asset AVReaderWriter avReaderWriter = new AVReaderWriter(contentEditingInput.AvAsset); avReaderWriter.Delegate = this; // Save filtered video avReaderWriter.WriteToUrl(contentEditingOutput.RenderedContentUrl, progress => { }, error => { if (error == null) { completionHandler(contentEditingOutput); return; } Console.WriteLine("An error occured: {0}", error); completionHandler(null); }); break; } default: break; } }