Example #1
0
File: Image.cs Project: pauZc/8_iOS
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            UIImageView i_image = new UIImageView();

            i_image.Frame = new CoreGraphics.CGRect(1, 65, 373, 170);
            i_image.Image = UIImage.FromBundle("cup.jpg");
            View.Add(i_image);

            UILabel lblScore = new UILabel();

            lblScore.Frame           = new CoreGraphics.CGRect(1, 320, 390, 70);
            lblScore.BackgroundColor = UIColor.FromRGB(246, 246, 246);
            lblScore.TextAlignment   = UITextAlignment.Right;


            var btnFavorite2 = new UIButton(UIButtonType.Custom);

            btnFavorite2.Frame = new CoreGraphics.CGRect(10, 65, 40, 40);
            string image = "twitter.png";

            MSCognitiveService cognser = new MSCognitiveService();

            byte[] imagen            = GetBitmapFromCache();
            string descripcionImagen = cognser.PeticionImagenDescripcion(imagen);

            lblScore.Text = descripcionImagen;
            View.Add(lblScore);
            btnFavorite2.SetImage(UIImage.FromBundle(image), UIControlState.Normal);
            btnFavorite2.TouchUpInside += delegate
            {
                try
                {
                    TWPublicarTweet twtwit  = new TWPublicarTweet();
                    string          MediaId = twtwit.ObtenerIdImagen(imagen);
                    if (!twtwit.PeticionPublicarTweet("Proyecto PDMII ISSC,MSCognitiveService.DescripciĆ³n obtenida: " + descripcionImagen, MediaId))
                    {
                        new UIAlertView("ERROR", "no se compartio", null, "ok", null).Show();
                    }
                }
                catch (Exception ex)
                {
                    new UIAlertView("ERROR", ex.Message, null, "ok", null).Show();
                }
            };
            View.Add(btnFavorite2);
            // Perform any additional setup after loading the view, typically from a nib.
        }
Example #2
0
        // This is a sample method that handles the FinishedPickingMediaEvent
        protected void Handle_FinishedPickingMedia(object sender, UIImagePickerMediaPickedEventArgs e)
        {
            // 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;
            }

            Console.Write("Reference URL: [" + UIImagePickerController.ReferenceUrl + "]");

            // get common info (shared between images and video)
            NSUrl referenceURL = e.Info[new NSString("UIImagePickerControllerReferenceUrl")] as NSUrl;

            if (referenceURL != null)
            {
                Console.WriteLine(referenceURL.ToString());
            }

            // if it was an image, get the other image info
            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");
                    imageView.Image = originalImage;
                }

                // get the edited image
                UIImage editedImage = e.Info[UIImagePickerController.EditedImage] as UIImage;
                if (editedImage != null)
                {
                    // do something with the image
                    Console.WriteLine("got the edited image");
                    imageView.Image = editedImage;
                }

                //- get the image metadata
                NSDictionary imageMetadata = e.Info[UIImagePickerController.MediaMetadata] as NSDictionary;
                if (imageMetadata != null)
                {
                    // do something with the metadata
                    Console.WriteLine("got image metadata");
                }
            }
            // if it's a video
            else
            {
                // get video url
                NSUrl mediaURL = e.Info[UIImagePickerController.MediaURL] as NSUrl;
                if (mediaURL != null)
                {
                    //
                    Console.WriteLine(mediaURL.ToString());
                }
            }

            // dismiss the picker
            imagePicker.DismissModalViewController(true);
            UITextView lblScore = new UITextView();

            lblScore.Frame           = new CoreGraphics.CGRect(1, 500, 370, 70);
            lblScore.BackgroundColor = UIColor.FromRGB(246, 246, 246);
            lblScore.TextAlignment   = UITextAlignment.Center;
            UIImage imagenT      = imageView.Image;
            NSData  imageData    = imagenT.AsPNG();
            var     btnFavorite2 = new UIButton(UIButtonType.Custom);

            btnFavorite2.Frame = new CoreGraphics.CGRect(10, 400, 40, 40);
            string image = "twitter.png";

            byte[] myArr = new Byte[imageData.Length];
            System.Runtime.InteropServices.Marshal.Copy(imageData.Bytes, myArr, 0, Convert.ToInt32(imageData.Length));
            MSCognitiveService cognser           = new MSCognitiveService();
            string             descripcionImagen = cognser.PeticionImagenDescripcion(myArr);

            lblScore.Text = descripcionImagen;
            View.Add(lblScore);
            btnFavorite2.SetImage(UIImage.FromBundle(image), UIControlState.Normal);
            btnFavorite2.TouchUpInside += delegate
            {
                try
                {
                    TWPublicarTweet twtwit  = new TWPublicarTweet();
                    string          MediaId = twtwit.ObtenerIdImagen(myArr);
                    if (!twtwit.PeticionPublicarTweet("Proyecto PDMII ISSC,MSCognitiveService.DescripciĆ³n obtenida: " + descripcionImagen, MediaId))
                    {
                        new UIAlertView("ERROR", "no se compartio", null, "ok", null).Show();
                    }
                }
                catch (Exception ex)
                {
                    new UIAlertView("ERROR", ex.Message, null, "ok", null).Show();
                }
            };
            View.Add(btnFavorite2);
        }