Exemple #1
0
        public void UploadFoodMarkerPhotosToDir()
        {
            if (!Directory.Exists(_path))
            {
                Directory.CreateDirectory(_path);
            }
            ClearFoodMarkerPhotosDir();

            int i = 0;

            foreach (var meta in _marker.FoodMarkerPhotos)
            {
                UIImage im;
                using (var url = new NSUrl(meta.ImageUrl))
                {
                    using (var data = NSData.FromUrl(url))
                    {
                        im = UIImage.LoadFromData(data);
                    }
                }
                using (NSData data = im.AsPNG())
                {
                    byte[] buffer = new byte[data.Length];
                    System.Runtime.InteropServices.Marshal.Copy(data.Bytes, buffer, 0, Convert.ToInt32(data.Length));
                    _directoryAccess.UploadFile(buffer, Path.Combine(_path, i.ToString() + ".png"));
                }
                i++;
            }
        }
 public void SaveMediaToPending(UIImage image)
 {
     using (NSData data = image.AsPNG())
     {
         byte[] buffer = new byte[data.Length];
         System.Runtime.InteropServices.Marshal.Copy(data.Bytes, buffer, 0, Convert.ToInt32(data.Length));
         _directoryAccess.UploadFile(buffer, _index.ToString() + ".png");
         _index++;
     }
 }
        public FoodMarkerAnnotation LoadAnnotations(FoodMarker marker)
        {
            FoodMarkerAnnotation annotation = new FoodMarkerAnnotation(marker);

            annotation.imgFileName = marker.FoodMarkerId.ToString();

            UIImage uiImage;

            if (marker.FoodMarkerPhotos != null &&
                marker.FoodMarkerPhotos.Where(p => p.ImageRank == 1).Any())
            {
                var iconImage = marker.FoodMarkerPhotos.Where(p => p.ImageRank == 1).First();

                using (var url = new NSUrl(iconImage.ImageUrl))
                {
                    using (var data = NSData.FromUrl(url))
                    {
                        if (data != null)
                        {
                            uiImage = UIImage.LoadFromData(data);
                        }
                        else
                        {
                            uiImage = UIImage.FromBundle("DataBox");
                        }
                    }
                }
            }
            else
            {
                uiImage = UIImage.FromBundle("DataBox");
            }

            uiImage = uiImage.Scale(new CGSize(MapSettings.AnnotationSize.Width,
                                               MapSettings.AnnotationSize.Height));

            using (NSData data = uiImage.AsPNG())
            {
                byte[] buffer = new byte[data.Length];
                System.Runtime.InteropServices.Marshal.Copy(data.Bytes, buffer, 0, Convert.ToInt32(data.Length));
                _directoryAccess.UploadFile(buffer, annotation.imgFileName);
            }

            return(annotation);
        }