コード例 #1
0
        public void Handle_FinishedPickingMedia(object sender, UIImagePickerMediaPickedEventArgs e)
        {
            var originalImage = e.Info[UIImagePickerController.OriginalImage] as UIImage;

            var meta = e.Info[UIImagePickerController.MediaMetadata] as NSDictionary;

            try
            {
                if (originalImage != null)
                {
                    var documentsDirectory = Environment.GetFolderPath
                                                 (Environment.SpecialFolder.Personal);
                    string buttonName = "additional-photo-" + selected_index + ".png";
                    AppDelegate.appDelegate.photoButtonClicked = buttonName;
                    string  pngFilename = System.IO.Path.Combine(documentsDirectory, buttonName);
                    NSData  imgData     = originalImage.AsJPEG(0.0f);
                    NSError err         = null;
                    if (imgData.Save(pngFilename, false, out err))
                    {
                        Console.WriteLine("saved as " + pngFilename);
                    }
                    else
                    {
                        Console.WriteLine("NOT saved as" + pngFilename + " because" + err.LocalizedDescription);
                    }


                    SetAdditionalImages(pngFilename);
                    var    imagea             = UIImage.LoadFromData(imgData);
                    var    currentOrientation = UIApplication.SharedApplication.StatusBarOrientation;
                    string Orientaion         = "Landscape";
                    if (iSCamera)
                    {
                        if (currentOrientation == UIInterfaceOrientation.Portrait)
                        {
                            Orientaion = "Portrait";
                        }
                        else
                        {
                            Orientaion = "Landscape";
                        }
                    }
                    iSCamera = false;
                    NSData imageData = originalImage.AsJPEG(0.0f);

                    Byte[] myByteArray = new Byte[imageData.Length];
                    System.Runtime.InteropServices.Marshal.Copy(imageData.Bytes, myByteArray, 0, Convert.ToInt32(imageData.Length));

                    // save photos to Azure cloud
                    imagePicker.DismissModalViewController(true);
                    Amazon.Aws amazonS3 = new Amazon.Aws();
                    Task.Run(() => amazonS3.UploadFile(pngFilename, myByteArray, Orientaion));
                    ActivityLoader();
                }
            }
            catch (Exception exc)
            {
                Console.WriteLine("Exception occured :: " + exc.Message);
            }

            // dismiss the picker
            //imagePicker.DismissModalViewController(true);
            //imagePicker.DismissModalViewControllerAnimated(true);
        }
コード例 #2
0
        public void Handle_FinishedPickingMedia(object sender, UIImagePickerMediaPickedEventArgs e)
        {
            var originalImage = e.Info[UIImagePickerController.OriginalImage] as UIImage;

            var meta = e.Info[UIImagePickerController.MediaMetadata] as NSDictionary;

            try
            {
                if (originalImage != null)
                {
                    Console.WriteLine("got the original image");
                    //Right_Image.SetBackgroundImage(originalImage, UIControlState.Normal);

                    //imageView.Image = originalImage; // display
                    setImage(originalImage);
                    var documentsDirectory = Environment.GetFolderPath
                                                 (Environment.SpecialFolder.Personal);
                    string  buttonName  = currentButton + ".png";
                    string  pngFilename = System.IO.Path.Combine(documentsDirectory, buttonName);
                    NSData  imgData     = originalImage.AsJPEG(0.0f);
                    NSError err         = null;
                    if (imgData.Save(pngFilename, false, out err))
                    {
                        Console.WriteLine("saved as " + pngFilename);
                    }
                    else
                    {
                        Console.WriteLine("NOT saved as" + pngFilename + " because" + err.LocalizedDescription);
                    }

                    //ALAssetsLibrary library = new ALAssetsLibrary();

                    //library.WriteImageToSavedPhotosAlbum(originalImage.CGImage, meta, (assetUrl, error) => {
                    //    Console.WriteLine("assetUrl:" + assetUrl);
                    //});
                    var imagea = UIImage.LoadFromData(imgData);

                    //imagea.SaveToPhotosAlbum((AppraisalPhotoAlbum, eror) =>
                    //{

                    //});
                    var    currentOrientation = UIApplication.SharedApplication.StatusBarOrientation;
                    string Orientaion         = "Landscape";
                    if (iSCamera)
                    {
                        if (currentOrientation == UIInterfaceOrientation.Portrait)
                        {
                            Orientaion = "Portrait";
                        }
                        else
                        {
                            Orientaion = "Landscape";
                        }
                    }
                    iSCamera = false;
                    NSData imageData = originalImage.AsJPEG(0.0f);

                    byte[] myByteArray = new byte[imageData.Length];
                    System.Runtime.InteropServices.Marshal.Copy(imageData.Bytes, myByteArray, 0, Convert.ToInt32(imageData.Length));

                    imagePicker.DismissModalViewController(true);
                    Amazon.Aws amazonS3 = new Amazon.Aws();
                    Task.Run(() => amazonS3.UploadFile(pngFilename, myByteArray, Orientaion));
                    ActivityLoader();
                }
            }
            catch (Exception exc)
            {
                Console.WriteLine("Exception occured :: " + exc.Message);
            }

            // dismiss the picker
            //imagePicker.DismissModalViewController(true);
            //imagePicker.DismissModalViewControllerAnimated(true);
        }