Beispiel #1
0
        private void FinalizandoSeleccion(object sender, UIImagePickerMediaPickedEventArgs e)
        {
            Fotografia = e.Info[UIImagePickerController.OriginalImage] as UIImage; //Se captura la inagen de tipo Image que es la imagen que esta ingresando al evento.

            imagenes.Image = Fotografia;                                           //Se envia al componente grafico.

            Fotografia.SaveToPhotosAlbum(delegate(UIImage imagen, NSError error)
            {
                if (null != error)                                 //Si, el error contiene información, debe mostrarla.
                {
                    Console.WriteLine(error.LocalizedDescription); //muestra la información del error
                }
            }
                                         );

            Fotografia.AsJPEG();                                                                //Almacena en el album de photografias.

            string rutaCarpeta = Environment.GetFolderPath(Environment.SpecialFolder.Personal); //Ruta del dispositivo

            string nombreArchivo = "Foto01.jpg";                                                //nombre del archivo

            string rutaCompleta = Path.Combine(rutaCarpeta, nombreArchivo);

            NSError err = null;

            NSData img = Fotografia.AsJPEG();  //Almacena en el album de photografias, Se selecciona la imagen que esta guardad localmente.

            img.Save(rutaCompleta, false, out err);

            imagenes.Image = UIImage.FromFile(rutaCompleta);

            SeleccionImagen.DismissViewControllerAsync(true);
        }
Beispiel #2
0
		public override void FinishedPickingImage (UIImagePickerController picker, UIImage image, NSDictionary editingInfo)
		{	
			UIApplication.SharedApplication.SetStatusBarHidden(false, false);
			
			var imagePicker = (VCViewController)_navigationController;
			if (imagePicker.IsCameraAvailable)
				imagePicker.btnBib.Hidden = true;
						
			imagePicker.DismissModalViewControllerAnimated(true);
			
			if (imagePicker.IsCameraAvailable)
			{
				image.SaveToPhotosAlbum (delegate {
					// ignore errors
					});
			}
			
			UIViewController nextScreen = null;
			
			if (tweet != null)
			{
				nextScreen = new PhotoPostViewController(_shareNavCont, image, tweet);
			}
			else
			{
				nextScreen = new PhotoLocationViewController(_shareNavCont, image);				
			}
			
			_shareNavCont.PushViewController(nextScreen, true);
		}	
Beispiel #3
0
        public void SavePicButton(UIButton button)
        {
            UIImage _filteredImage = new UIImage();

            _filteredImage.SaveToPhotosAlbum((image, err2) => {
                if (err2 != null)
                {
                    Console.WriteLine("error saving image: {0}",
                                      err2);
                }
                else
                {
                    Console.WriteLine("image saved to photo album");
                }
            });

            //UIImageWriteToSavedPhotosAlbum(image.Image, null, null, null);

            UIAlertController alert = UIAlertController.Create("Image filtered",
                                                               "Your image has been saved to your library",
                                                               UIAlertControllerStyle.Alert);

            alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null));

            PresentViewController(alert, true, null);
        }
        public async Task <string> CaptureAndSaveAsync()
        {
            var bytes = await CaptureAsync();

            var    documentsDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
            string date = DateTime.Now.ToString().Replace("/", "-").Replace(":", "-");

            try
            {
                string localPath = System.IO.Path.Combine(documentsDirectory, "Screnshot-" + date + ".png");

                var chartImage = new UIImage(NSData.FromArray(bytes));
                chartImage.SaveToPhotosAlbum((image, error) =>
                {
                    //you can retrieve the saved UI Image as well if needed using
                    if (error != null)
                    {
                        Console.WriteLine(error.ToString());
                    }
                });
                return(localPath);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Beispiel #5
0
        partial void btnSnap_TouchUpInside(UIButton sender)
        {
            UIGraphics.BeginImageContext(UIScreen.MainScreen.ApplicationFrame.Size);
            try {
                var mainLayer = MainView.Layer;
                mainLayer.RenderInContext(UIGraphics.GetCurrentContext());
                var     orientation = UIApplication.SharedApplication.StatusBarOrientation;
                var     img         = UIScreen.MainScreen.Capture();
                UIImage screenshot  = null;
                if (orientation == UIInterfaceOrientation.LandscapeLeft)
                {
                    screenshot = UIImage.FromImage(img.CGImage, 1f, UIImageOrientation.Right);
                }
                else if (orientation == UIInterfaceOrientation.LandscapeRight)
                {
                    screenshot = UIImage.FromImage(img.CGImage, 1f, UIImageOrientation.Left);
                }

                screenshot.SaveToPhotosAlbum((iRef, status) => {
                    if (status != null)
                    {
                        new UIAlertView("Problem", status.ToString(), null, "OK", null).Show();
                    }
                    else
                    {
                        new UIAlertView("Screenshot", "Screenshot is Saved", null, "OK", null).Show();
                    }
                });
            } finally {
                UIGraphics.EndImageContext();
            }
        }
Beispiel #6
0
        public void CapturePicture(Action <UIImage, NSError> completion)
        {
            if (!cameraIsSetup)
            {
                return;
            }

            if (_outputMode != CameraOutputMode.StillImage)
            {
                return;
            }

            NSData imageData;

            _getStillImageOutput().CaptureStillImageAsynchronously(
                stillImageOutput.ConnectionFromMediaType(AVMediaType.Video),
                (imageDataSampleBuffer, error) =>
            {
                if (imageDataSampleBuffer == null)
                {
                    return;
                }

                imageData = AVCaptureStillImageOutput.JpegStillToNSData(imageDataSampleBuffer);

                var image = new UIImage(imageData);
                image.SaveToPhotosAlbum((img, err) =>
                {
                    completion(img, err);
                });
            });
        }
        public void SaveImageFromByte(byte[] imageByte, string fileName)
        {
            var imageData = new UIImage(NSData.FromArray(imageByte));

            PHPhotoLibrary.RequestAuthorization(status =>
            {
                switch (status)
                {
                case PHAuthorizationStatus.Restricted:
                case PHAuthorizationStatus.Denied:
                    // nope you don't have permission
                    break;

                case PHAuthorizationStatus.Authorized:

                    imageData.SaveToPhotosAlbum((image, error) =>
                    {
                        //you can retrieve the saved UI Image as well if needed using
                        //var i = image as UIImage;
                        if (error != null)
                        {
                            Console.WriteLine(error.ToString());
                        }
                    });
                    break;
                }
            });
        }
        public async Task <bool> SaveImage(byte[] Image)
        {
            savetcs = new TaskCompletionSource <bool>();
            bool wasSaved = false;

            var someImage = new UIImage(Foundation.NSData.FromArray(Image));;

            try
            {
                someImage.SaveToPhotosAlbum((image, error) => {
                    if (error != null)
                    {
                        wasSaved = false;
                    }
                    else
                    {
                        wasSaved = true;
                    }
                    savetcs.TrySetResult(wasSaved);
                });
            }
            catch (Exception ex)
            {
                wasSaved = false;
                savetcs.TrySetResult(wasSaved);
            }


            return(await savetcs.Task);
        }
 private void SaveImage(UIImage image)
 {
     DispatchQueue.MainQueue.DispatchAsync(() =>
     {
         image.SaveToPhotosAlbum((a, b) =>
         {
         });
     });
 }
Beispiel #10
0
        public Task <bool> SaveImageAsync(byte[] data, string filename, string folder = null)
        {
            NSData  nsData = NSData.FromArray(data);
            UIImage image  = new UIImage(nsData);
            TaskCompletionSource <bool> taskCompletionSource = new TaskCompletionSource <bool>();

            image.SaveToPhotosAlbum((UIImage img, NSError error) => taskCompletionSource.SetResult(error == null));

            return(taskCompletionSource.Task);
        }
 partial void BBSaveImageClick(UIBarButtonItem sender)
 {
     try
     {
         image.SaveToPhotosAlbum(HandleSaveStatus);
         BTProgressHUD.Dismiss();
     }
     catch (Exception ex)
     {
     }
 }
Beispiel #12
0
        public void MoveToAlbum(string path)
        {
            var     name = Path.GetFileName(path);
            var     documentsDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            string  jpgFilename        = System.IO.Path.Combine(documentsDirectory, name);
            UIImage currentImage       = UIImage.FromFile(jpgFilename);

            currentImage.SaveToPhotosAlbum((image, error) => {
                var o = image as UIImage;
                Console.WriteLine("error:" + error);
            });
        }
Beispiel #13
0
        public void SavePictureToDisk(string filename, byte[] imageData)
        {
            var image = new UIImage(NSData.FromArray(imageData));

            image.SaveToPhotosAlbum((imagefile, error) =>
            {
                if (error != null)
                {
                    Console.WriteLine(error);
                }
            });
        }
        public void SaveImageToStorage(byte[] imageData, string fileName)
        {
            var image = new UIImage(NSData.FromArray(imageData));

            image.SaveToPhotosAlbum((img, error) =>
            {
                if (error != null)
                {
                    Console.WriteLine("Saved");
                }
            });
        }
        async void CapturePhoto()
        {
            var videoConnection = stillImageOutput.ConnectionFromMediaType(AVMediaType.Video);
            var sampleBuffer    = await stillImageOutput.CaptureStillImageTaskAsync(videoConnection);

            var jpegImage = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);

            var photo = new UIImage(jpegImage);

            photo.SaveToPhotosAlbum((image, error) => {
                Console.Error.WriteLine(@"				Error: ", error);
            });
        }
Beispiel #16
0
        public void writeToGallery(string filename, byte[] imageData)
        {
            var p_image = new UIImage(NSData.FromArray(imageData));

            p_image.SaveToPhotosAlbum((image, error) =>
            {
                //var i = image as UIImage;
                if (error != null)
                {
                    Console.WriteLine(error.ToString());
                }
            });
        }
Beispiel #17
0
        private void SavePhoto(IEditableImage image)
        {
#if __IOS__
            var tmp = new UIImage(NSData.FromArray(image.ToPng()));
            tmp.BeginInvokeOnMainThread(() => {
                tmp.SaveToPhotosAlbum(new UIImage.SaveStatus((UIImage affs, NSError error) => {
                    ;
                }));
            });
#endif
#if __ANDROID__
#endif
        }
        public Task <bool> SaveBitmap(byte[] bitmapData, string filename)
        {
            NSData  data  = NSData.FromArray(bitmapData);
            UIImage image = new UIImage(data);
            TaskCompletionSource <bool> taskCompletionSource = new TaskCompletionSource <bool>();

            image.SaveToPhotosAlbum((UIImage img, NSError error) =>
            {
                taskCompletionSource.SetResult(error == null);
            });

            return(taskCompletionSource.Task);
        }
        /// <summary>
        /// Capture a copy of the current View and:
        /// * re-display in a UIImage control
        /// * save to the Photos collection
        /// * save to disk in the application's Documents folder
        /// </summary>
        public void ScreenCapture()
        {
            Console.WriteLine("start image cap");
            Console.WriteLine("frame" + this.View.Frame.Size);
            UIGraphics.BeginImageContext(View.Frame.Size);
            var documentsDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);

            var ctx = UIGraphics.GetCurrentContext();

            if (ctx != null)
            {
                Console.WriteLine("ctx not null");
                View.Layer.RenderInContext(ctx);
                Console.WriteLine("render in context");
                UIImage img = UIGraphics.GetImageFromCurrentImageContext();
                Console.WriteLine("get from current content");
                UIGraphics.EndImageContext();

                // Set to display in a UIImage control _on_ the view
                //imageLogo.Image = img;

                // Save to Photos
                img.SaveToPhotosAlbum((sender, args) =>
                {
                    Console.WriteLine("image saved to Photos");
                    var av = new UIAlertView("Screenshot saved", "Image saved to " + Environment.NewLine + "Photos : Camera Roll", null, "Ok thanks", null);
                    av.Show();
                });

                // thought this "might" overwrite the splashscreen
                //string png = Path.Combine (documentsDirectory, "../iSOFlair.app/Default.png");

                // Save to application's Documents folder, kinda pointless except as an example
                // since there is no way to "read" it
                string  png     = Path.Combine(documentsDirectory, "Screenshot.png");
                NSData  imgData = img.AsPNG();
                NSError err     = null;
                if (imgData.Save(png, false, out err))
                {
                    Console.WriteLine("saved " + png);
                }
                else
                {
                    Console.WriteLine("not saved" + png + " because" + err.LocalizedDescription);
                }
            }
            else
            {
                Console.WriteLine("ctx null - doesn't happen but wasn't sure at first");
            }
        }
Beispiel #20
0
 public static void SaveImageToPhotosApp(UIImage someImage, string filename)
 {
     try
     {
         someImage.SaveToPhotosAlbum((image, error) =>
         {
             var o = image as UIImage;
         });
     }
     catch (Exception e)
     {
         Console.WriteLine("error saving processed image: {0}", e.Message);
     }
 }
Beispiel #21
0
        public void SavePictureToDisk(string filename, byte[] imageData)
        {
            var image = new UIImage(NSData.FromArray(imageData));

            image.SaveToPhotosAlbum((_image, error) =>
            {
                //you can retrieve the saved UI Image as well if needed using
                //var i = image as UIImage;
                if (error != null)
                {
                    Console.WriteLine(error.ToString());
                }
            });
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            HandleFinishedPickingMedia = new Action <UIImagePickerController, NSDictionary> (
                delegate(UIImagePickerController picker, NSDictionary info) {
                UIImage im = (UIImage)info.ObjectForKey(UIImagePickerController.OriginalImage);
                NSError err;
                string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal),
                                           String.Format("{0}_{1}_{2}.jpg", _customerNumber.ToString(),
                                                         DateTime.Now.Date.ToString("yyyy-MM-dd"),
                                                         _photosCounter.ToString()));
                _photosCounter++;

                im = TakePhotosViewController.ScaleImage(im, 500);

                im.AsJPEG().Save(path, true, out err);
                im.SaveToPhotosAlbum(null);
                im.Dispose(); im = null;

                // error handling here according to NSError err
                if (err != null)
                {
                    using (var alert = new UIAlertView("Error:" + err.LocalizedDescription, "Unable to save image to: " + path, null, "OK", null)) {
                        alert.Show();
                    }
                    err.Dispose();
                    err = null;
                }

                picker.DismissViewController(true, null);                          // _ipc.DismissModalViewControllerAnimated (true);
                _tabs.SelectedViewController = _tabs.ViewControllers [_tabs.LastSelectedTab];
                _tabs._jobRunTable.TableView.SelectRow(_tabs._jobRunTable.LastSelectedRowPath, true, UITableViewScrollPosition.None);
            });

            HandleCanceledPickingMedia = new Action <UIImagePickerController> (
                delegate(UIImagePickerController picker) {
                if (!(_tabs.ViewControllers[_tabs.LastSelectedTab] is TakePhotosViewController))
                {
                    _tabs.SelectedViewController = _tabs.ViewControllers [_tabs.LastSelectedTab];
                }
                else
                {
                    _tabs.SelectedViewController = _tabs.ViewControllers[0];
                }

                _tabs._jobRunTable.TableView.SelectRow(_tabs._jobRunTable.LastSelectedRowPath, true, UITableViewScrollPosition.None);
                picker.DismissViewController(true, null);
            });
        }
Beispiel #23
0
        private void SaveToPhotosAlbum(UIImage image)
        {
            if (!Configuration.SaveToPhotosAlbum)
            {
                return;
            }

            image.SaveToPhotosAlbum((uiImage, nsError) =>
            {
                if (nsError != null)
                {
                    SaveToPhotosAlbumError?.Invoke(this, nsError);
                }
            });
        }
        partial void doTakeSnapshot(UIBarButtonItem sender)
        {
            UIImage img = new UIImage(flexPie.GetImage());

            img.SaveToPhotosAlbum((image, error) => {
                if (error == null)
                {
                    new UIAlertView("Success", "Image was saved to Camera Roll succesfully", null, "OK", null).Show();
                }
                else
                {
                    new UIAlertView("Failure", error.Description, null, "OK", null).Show();
                }
            });
        }
Beispiel #25
0
        async public void SavePictureToDisk(string filename, Task <byte[]> imageData)
        {
            NSData data       = NSData.FromArray(await imageData);
            var    chartImage = new UIImage(data);

            chartImage.SaveToPhotosAlbum((image, error) =>
            {
                //you can retrieve the saved UI Image as well if needed using
                //var i = image as UIImage;
                if (error != null)
                {
                    System.Diagnostics.Debug.WriteLine(error.ToString());
                }
            });
        }
Beispiel #26
0
        public Task <string> SaveImageToLibrary(Stream image, string filename)
        {
            if (image == null)
            {
                return(Task.FromResult <string>(null));
            }

            var tcs = new TaskCompletionSource <string>();

            using (var uiImage = new UIImage(NSData.FromStream(image)))
            {
                uiImage.SaveToPhotosAlbum((img, err) => tcs.TrySetResult(err != null ? null : filename));
            }
            return(tcs.Task);
        }
Beispiel #27
0
        void OnPhotoChosen(UIImagePickerController picker, UIImage photo)
        {
            Photograph = PhotoManager.ScaleToSize(photo, (int)PhotoWidth, (int)PhotoHeight);

            if (picker.SourceType == UIImagePickerControllerSourceType.Camera)
            {
                photo.SaveToPhotosAlbum(OnPhotoSaved);
            }
            else
            {
                photo.Dispose();
            }

            popover.Dismiss(true);
        }
Beispiel #28
0
        public void SavePicture(string filename, byte[] imgdata)
        {
            var charImage = new UIImage(NSData.FromArray(imgdata));

            charImage.SaveToPhotosAlbum((image, error) =>
            {
                if (error != null)
                {
                    Console.WriteLine("\n========================================");
                    Console.WriteLine("========================================");
                    Console.WriteLine("\n" + error.ToString());
                    Console.WriteLine("========================================");
                    Console.WriteLine("========================================\n");
                }
            });
        }
Beispiel #29
0
        public string SavePictureToDisk(string filename, string folder, byte[] imageData)
        {
            var chartImage = new UIImage(NSData.FromArray(imageData));

            chartImage.SaveToPhotosAlbum((image, error) =>
            {
                //you can retrieve the saved UI Image as well if needed using
                var i = image as UIImage;

                if (error != null)
                {
                    Console.WriteLine(error.ToString());
                }
            });
            return(String.Empty);
        }
Beispiel #30
0
        async void CapturePhoto()
        {
            var videoConnection = stillImageOutput.ConnectionFromMediaType(AVMediaType.Video);
            var sampleBuffer    = await stillImageOutput.CaptureStillImageTaskAsync(videoConnection);

            var jpegImage = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);

            var photo = new UIImage(jpegImage);

            photo.SaveToPhotosAlbum((image, error) =>
            {
                if (!string.IsNullOrEmpty(error?.LocalizedDescription))
                {
                    Console.Error.WriteLine($"\t\t\tError: {error.LocalizedDescription}");
                }
            });
        }
Beispiel #31
0
        public async Task CapturePhoto()
        {
            var videoConnection = stillImageOutput.ConnectionFromMediaType(AVMediaType.Video);
            var sampleBuffer    = await stillImageOutput.CaptureStillImageTaskAsync(videoConnection);


            var jpegImageAsNsData = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);


            var image = new UIImage(jpegImageAsNsData);

            image.SaveToPhotosAlbum(null);

            var toast = new MDToast("Une photo est disponible dans votre bibliothèque", 2);

            toast.Show();
        }
        void OnPhotoChosen(UIImagePickerController picker, UIImage photo)
        {
            Photograph = PhotoManager.ScaleToSize (photo, (int) PhotoWidth, (int) PhotoHeight);

            if (picker.SourceType == UIImagePickerControllerSourceType.Camera)
                photo.SaveToPhotosAlbum (OnPhotoSaved);
            else
                photo.Dispose ();

            popover.Dismiss (true);
        }
			public override void FinishedPickingImage (UIImagePickerController picker, UIImage image, NSDictionary editingInfo)
			{
				if (picker.SourceType == UIImagePickerControllerSourceType.Camera)
				{
					image.SaveToPhotosAlbum(delegate(UIImage savedImage, NSError error) {
						_controller.SaveImage(savedImage);
					});
				}
				else 
				{
					_controller.SaveImage(image);
				}
				picker.DismissModalViewControllerAnimated(true);
			}