private MediaFile GetPictureMediaFile(NSDictionary info) { var image = (UIImage)info[UIImagePickerController.EditedImage]; if (image == null) { image = (UIImage)info[UIImagePickerController.OriginalImage]; } String path = GetOutputPath( MediaPicker.TypeImage, options.Directory ?? ((IsCaptured) ? String.Empty : "temp"), options.Name); using (FileStream fs = File.OpenWrite(path)) using (Stream s = new NSDataStream(image.AsJPEG())) { s.CopyTo(fs); fs.Flush(); } Action <Boolean> dispose = null; if (source != UIImagePickerControllerSourceType.Camera) { dispose = d => File.Delete(path); } return(new MediaFile(path, () => File.OpenRead(path), dispose)); }
public Task <MediaFile> SaveThumbnailAsync(string path) { if (path == null) { throw new ArgumentNullException("path"); } return(Task <MediaFile> .Factory.StartNew(s => { string p = (string)s; using (UIImage img = GetThumbnail()) { if (img == null) { return null; } using (NSDataStream stream = new NSDataStream(img.AsJPEG())) using (Stream fs = File.OpenWrite(p)) { stream.CopyTo(fs); fs.Flush(); } } return new MediaFile(p, () => File.OpenRead(path)); }, path)); }
public Task<MediaFile> SaveThumbnailAsync (string path) { if (path == null) throw new ArgumentNullException ("path"); return Task<MediaFile>.Factory.StartNew (s => { string p = (string) s; using (UIImage img = GetThumbnail()) { if (img == null) return null; using (NSDataStream stream = new NSDataStream (img.AsJPEG())) using (Stream fs = File.OpenWrite (p)) { stream.CopyTo (fs); fs.Flush(); } } return new MediaFile (p, () => File.OpenRead (path)); }, path); }
private MediaFile GetPictureMediaFile( NSDictionary info ) { var image = (UIImage)info[UIImagePickerController.EditedImage]; if(image == null) { image = (UIImage)info[UIImagePickerController.OriginalImage]; } String path = GetOutputPath( MediaPicker.TypeImage, options.Directory ?? ((IsCaptured) ? String.Empty : "temp"), options.Name ); using(FileStream fs = File.OpenWrite( path )) using(Stream s = new NSDataStream( image.AsJPEG() )) { s.CopyTo( fs ); fs.Flush(); } Action<Boolean> dispose = null; if(source != UIImagePickerControllerSourceType.Camera) { dispose = d => File.Delete( path ); } return new MediaFile( path, () => File.OpenRead( path ), dispose ); }
public MediaFile GetPictureMediaFile(UIImage image) { string path = GetOutputPath (MediaPicker.TypeImage, "temp", options.Name); using (FileStream fs = File.OpenWrite (path)) using (Stream s = new NSDataStream (image.AsJPEG ())) { s.CopyTo (fs); fs.Flush (); } Action<bool> dispose = null; dispose = d => File.Delete (path); return new MediaFile (path, () => File.OpenRead (path), dispose); }