Ejemplo n.º 1
0
        protected async void Handle_FinishedPickingMedia(object sender, UIImagePickerMediaPickedEventArgs e)
        {
            try
            {
                //Console.WriteLine("Enterd into Gallery pick");
                // determine what was selected, video or image
                bool isImage = false;
                switch (e.Info[UIImagePickerController.MediaType].ToString())
                {
                case "public.image":
                    //Console.WriteLine("Image selected");
                    isImage = true;
                    break;

                case "public.video":
                    //Console.WriteLine("Video selected");
                    break;
                }
                if (isImage)
                {
                    // get the original image

                    UIImage originalImage = e.Info[UIImagePickerController.OriginalImage] as UIImage;
                    if (originalImage != null)
                    {
                        // do something with the image

                        //Console.WriteLine("got the original image");
                        imgprofilepic.Image = originalImage;                         // display
                        using (NSData imagedata = originalImage.AsJPEG())
                        {
                            byte[] myByteArray = new byte[imagedata.Length];
                            System.Runtime.InteropServices.Marshal.Copy(imagedata.Bytes,
                                                                        myByteArray, 0, Convert.ToInt32(imagedata.Length));

                            byte[] img = BlobWrapper.ResizeImageIOS(myByteArray, 250, 300);
                            int    i   = img.Length;
                            await BlobWrapper.UploadProfilePic(img, i);
                        }
                    }
                }
                else
                {                 // if it's a video
                                  // get video url
                    NSUrl mediaURL = e.Info[UIImagePickerController.MediaURL] as NSUrl;
                    if (mediaURL != null)
                    {
                        //Console.WriteLine(mediaURL.ToString());
                    }
                }
                // dismiss the picker
                imagePicker.DismissModalViewController(true);
            }
            catch (Exception ex)
            {
                LoggingClass.LogError(ex.ToString(), screenid, ex.StackTrace);
            }
        }
 //public override void ViewDidAppear(bool animated)
 //{
 //	base.ViewDidAppear(animated);
 //	//NavigationController.Title = "Locations";
 //	//NavigationController.NavigationBar.TopItem.Title = "Locations";
 //	string validUser = CurrentUser.RetreiveUserName();
 //	LoggingClass.LogInfo("opened app " + validUser, screenid);
 //	if (validUser == "" || validUser == null)
 //	{
 //		LoginViewController yourController = new LoginViewController();
 //		yourController.nav = NavigationController;
 //		yourController.root = this;
 //		yourController.ModalPresentationStyle = UIModalPresentationStyle.FullScreen;
 //		this.PresentModalViewController(yourController, false);
 //	}
 //}
 public async void UploadProfilePic(UIImage originalImage)
 {
     if (originalImage != null)
     {
         imgProfile.Image = originalImage;                 // display
         using (NSData imagedata = originalImage.AsJPEG())
         {
             byte[] myByteArray = new byte[imagedata.Length];
             System.Runtime.InteropServices.Marshal.Copy(imagedata.Bytes, myByteArray, 0, Convert.ToInt32(imagedata.Length));
             byte[] img = BlobWrapper.ResizeImageIOS(myByteArray, 250, 300);
             int    i   = img.Length;
             await BlobWrapper.UploadProfilePic(img, i);
         }
     }
 }