private void Handle_FinishedPickingMedia(object sender, UIImagePickerMediaPickedEventArgs e)
        {
            if (e.Info[UIImagePickerController.OriginalImage] is UIImage originalImage)
            {
                NSData imageData    = originalImage.AsPNG();
                string encodedImage = imageData.GetBase64EncodedData(NSDataBase64EncodingOptions.None).ToString();
                OnGetImageFromGallery?.Invoke(encodedImage);
            }

            ImagePicker.DismissModalViewController(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Saves UIKit.UIImage by key (If database is not exist, it will be created).
        /// </summary>
        /// <param name="key">The key (If the key invalid, value will not be saved).</param>
        /// <param name="imageValue">The image value.</param>
        public void SaveData(string key, UIImage imageValue)
        {
            if (string.IsNullOrWhiteSpace(key))
            {
                return;
            }

            CreateIfNotExist();

            NSData imageData    = imageValue.AsPNG();
            string encodedImage = imageData.GetBase64EncodedData(NSDataBase64EncodingOptions.None).ToString();

            SaveData(key, encodedImage);
        }
Esempio n. 3
0
        public void CacheImage(string imageUrl)
        {
            using (var url = new NSUrl(imageUrl))
                using (var data = NSData.FromUrl(url))
                {
                    if (data == null)
                    {
                        return;
                    }

                    NSData imageData    = UIImage.LoadFromData(data)?.AsPNG();
                    string encodedImage = imageData?.GetBase64EncodedData(NSDataBase64EncodingOptions.None).ToString();

                    Presenter.SaveCachedImage(encodedImage);
                }
        }
Esempio n. 4
0
        void WriteToFile(NSData nsdata)
        {
            try {
                // string encoded = Base64.EncodeToString(localdata, Base64Flags.Default);
                string encoded = nsdata.GetBase64EncodedData(NSDataBase64EncodingOptions.SixtyFourCharacterLineLength).ToString();//Convert.ToBase64String(localdata);
                //txtoutput.Text = encoded;
                //txtoutput.SizeToFit();
                //txtoutput.LayoutIfNeeded();

                if (MFMailComposeViewController.CanSendMail)
                {
                    mailController = new MFMailComposeViewController();

                    // do mail operations here
                    mailController.SetToRecipients(new string[] { "*****@*****.**" });
                    mailController.SetSubject("mail test");
                    mailController.SetMessageBody("this is a test " + encoded, false);

                    mailController.Finished += (object s, MFComposeResultEventArgs args) =>
                    {
                        Console.WriteLine(args.Result.ToString());
                        args.Controller.DismissViewController(true, null);
                    };

                    this.PresentViewController(mailController, true, null);
                }


                //var documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);

                //if (!System.IO.Directory.Exists(documentsPath.ToString())) {
                //    Directory.CreateDirectory(documentsPath.ToString());
                //}

                //var filePath = Path.Combine(documentsPath, "image" + DateTime.Now.Ticks);

                //// In this line where i create FileStream i get an Exception
                //FileStream fileStream = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
                //using (var streamWriter = new StreamWriter(fileStream)) {
                //    streamWriter.Write(encoded);
                //}
            }
            catch (Exception e) {
                Console.WriteLine(e.StackTrace);
            }
        }
Esempio n. 5
0
        private void SaveButton_TouchUpInside(object sender, EventArgs e)
        {
            if (!AreFieldsValid())
            {
                return;
            }

            MainTask newTask = new MainTask();

            newTask.Title   = titleTextField.Text;
            newTask.Date    = date;
            newTask.Time    = date;
            newTask.Comment = commentTextView.Text;
            if (img_UploadImage.CurrentImage != null)
            {
                NSData imageData = img_UploadImage.CurrentImage.AsJPEG(0.5f);

                string encodedImage = imageData.GetBase64EncodedData(NSDataBase64EncodingOptions.None).ToString();
                newTask.Image = encodedImage;
            }
            else
            {
                newTask.Image = "";
            }
            if (map != null)
            {
                newTask.Longtitude = map.Annotations[0].Coordinate.Longitude;
                newTask.Latitude   = map.Annotations[0].Coordinate.Latitude;
            }

            Database.saveTask(newTask);
            Console.WriteLine("Count = " + Database.CountTasks());

            Console.WriteLine("All Task");
            List <MainTask> allTasks = Database.GetAllTasks();

            foreach (MainTask t in allTasks)
            {
                Console.WriteLine(t);
            }

            Console.WriteLine("Today Tasks");
            List <MainTask> todays = Database.GetTodayTasks();

            foreach (MainTask t in todays)
            {
                Console.WriteLine(t);
            }

            #region CreateNotification
            var notification = new UILocalNotification();

            notification.FireDate = dateDatePicker.Date;

            notification.AlertAction = newTask.Title;
            notification.AlertBody   = newTask.Comment;

            notification.ApplicationIconBadgeNumber = 1;

            notification.SoundName = UILocalNotification.DefaultSoundName;

            UIApplication.SharedApplication.ScheduleLocalNotification(notification);
            #endregion

            NavigationController.PopViewController(true);
        }