Exemplo n.º 1
0
        public async Task <PhotoViewModel> ReadByAnnotation(int id, PhotoLoadType loadType = PhotoLoadType.Miniature)
        {
            var dig = new OpenFileDialog()
            {
                //TODO: Multi language support
                Title = "Chose the annotation file"
            };
            var photoLoader      = new PhotoLoader();
            var annotationLoader = new AnnotationLoader();

            var(path, stream) = await _reader.Read(dig);

            try
            {
                var annotation = annotationLoader.Load(path, stream);
                var photoPath  = Path.Combine(annotation.Folder, annotation.Filename);
                var photo      = await photoLoader.Load(photoPath, loadType);

                return(new PhotoViewModel(id, photo, annotation));
            }
            catch (Exception e)
            {
                throw new Exception($"unable to read image from {path}");
            }
        }
Exemplo n.º 2
0
        public async Task OpenFile(string inputPath)
        {
            try
            {
                Status = "loading photos...";
                _applicationStatusManager.ChangeCurrentAppStatus(Enums.Status.Working, "");
                using (var pb = new Models.ProgressBar())
                {
                    var count       = 0;
                    var id          = 0;
                    var photoLoader = new PhotoLoader();
                    var files       = GetFilesFromDir(inputPath, false);
                    var enumerable  = files as string[] ?? files.ToArray();
                    _photos.Clear();
                    foreach (var path in enumerable)
                    {
                        try
                        {
                            await using (var stream = File.OpenRead(path))
                            {
                                if (Path.GetExtension(path).ToLower() != ".jpg" &&
                                    Path.GetExtension(path).ToLower() != ".jpeg" &&
                                    Path.GetExtension(path).ToLower() != ".png")
                                {
                                    count++;
                                    continue;
                                }
                                var annotation = new Annotation
                                {
                                    Filename = Path.GetFileName(path),
                                    Folder   = Path.GetDirectoryName(path)
                                };
                                var photo = await photoLoader.Load(path, stream, PhotoLoadType.Miniature);

                                _photos.Add(new PhotoViewModel(id, photo, annotation));
                                id++;
                                count++;
                                InputProgress     = (double)count / enumerable.Count() * 100;
                                InputTextProgress = $"{Convert.ToInt32(InputProgress)} %";
                                _applicationStatusManager.ChangeCurrentAppStatus(Enums.Status.Working, $"Working | {(int)((double) count / enumerable.Count() * 100)} %, [{count} of {enumerable.Count()}]");
                                pb.Report((double)count / enumerable.Count(), $"Processed {count} of {enumerable.Count()}");
                            }
                        }
                        catch (Exception e)
                        {
                            Log.Warning(e, $"image from {path} is skipped!");
                        }
                    }
                }
                _selectedIndex = 0;
                _applicationStatusManager.ChangeCurrentAppStatus(Enums.Status.Ready, "");
                InputTextProgress = $"loads {_photos.Count} photos.";
                Log.Information($"Loads {_photos.Count} photos.");
            }
            catch (Exception ex)
            {
                Status = "error.";
                Log.Error(ex, "Unable to load photos.");
            }
        }
Exemplo n.º 3
0
        async void AddPhoto(object obj)
        {
            try
            {
                // выбор фото
                var   photopath = "";
                Image img       = new Image();
                if (CrossMedia.Current.IsPickPhotoSupported)
                {
                    MediaFile photo = await CrossMedia.Current.PickPhotoAsync();

                    photopath = photo.Path;
                }



                Photo c = new Photo()
                {
                    Id          = ++lastId,
                    AddedDate   = DateTime.Now,
                    ClientPhoto = File.ReadAllBytes(photopath)
                };
                Photos.Add(c);
                await PhotoLoader.AddPhoto(c);
            }
            catch { }
        }
Exemplo n.º 4
0
        public async Task <PhotoViewModel> ReadByPhoto(int id, PhotoLoadType loadType = PhotoLoadType.Miniature)
        {
            var dig = new OpenFileDialog()
            {
                //TODO: Multi language support
                Title = "Chose the image file"
            };
            var photoLoader = new PhotoLoader();

            var(path, stream) = await _reader.Read(dig);

            try
            {
                var photo = await photoLoader.Load(path, stream, loadType);

                var annotation = new Annotation
                {
                    Filename = Path.GetFileName(path),
                    Folder   = Path.GetDirectoryName(path)
                };
                return(new PhotoViewModel(id, photo, annotation));
            }
            catch (Exception e)
            {
                throw new Exception($"unable to read image from {path}");
            }
        }
 // Use this for initialization
 void Start()
 {
     p = go.GetComponent <PhotoLoader>();
     swipeRegisteredUp    = false;
     swipeRegisteredLeft  = false;
     swipeRegisteredRight = false;
 }
Exemplo n.º 6
0
        void HandleDone(object sender, System.EventArgs args)
        {
            Log.DebugTimerPrint(timer, "Loading image took {0}");
            IImageLoader loader = sender as IImageLoader;

            if (loader != this.loader)
            {
                return;
            }

            Pixbuf prev = this.Pixbuf;

            if (Pixbuf != loader.Pixbuf)
            {
                Pixbuf = loader.Pixbuf;
            }

            if (Pixbuf == null)
            {
                // FIXME: Do we have test cases for this ???

                // FIXME in some cases the image passes completely through the
                // pixbuf loader without properly loading... I'm not sure what to do about this other
                // than try to load the image one last time.
                try {
                    Log.Warning("Falling back to file loader");
                    Pixbuf = PhotoLoader.Load(item.Collection, item.Index);
                } catch (Exception e) {
                    LoadErrorImage(e);
                }
            }

            if (loader.Pixbuf != null)             //FIXME: this test in case the photo was loaded with the direct loader
            {
                PixbufOrientation = Accelerometer.GetViewOrientation(loader.PixbufOrientation);
            }
            else
            {
                PixbufOrientation = ImageOrientation.TopLeft;
            }

            if (Pixbuf == null)
            {
                LoadErrorImage(null);
            }
            else
            {
                ZoomFit();
            }

            progressive_display = true;

            if (prev != this.Pixbuf && prev != null)
            {
                prev.Dispose();
            }
        }
Exemplo n.º 7
0
        protected void odsPhotoAlbum_Selected(object sender, ObjectDataSourceStatusEventArgs e)
        {
            IEnumerable <Model.Photo> retvalue = (IEnumerable <Model.Photo>)e.ReturnValue;

            if (retvalue.Count() == 0)
            {
                return;
            }
            imgMain.ImageUrl = PhotoLoader.GenerateLinkForPhoto(retvalue.First().FileName);
        }
Exemplo n.º 8
0
        public async Task <PhotoViewModel[]> ReadAllFromDirByPhoto(PhotoLoadType loadType = PhotoLoadType.Miniature, bool isRecursive = false)
        {
            var dig = new OpenFolderDialog()
            {
                //TODO: Multi language support
                Title = "Chose directory image files"
            };
            var multipleFiles = await _reader.ReadAllFromDir(dig, isRecursive);

            var photoLoader = new PhotoLoader();
            var photoList   = new List <PhotoViewModel>();
            var count       = 0;
            var id          = 0;
            var valueTuples = multipleFiles as (string Path, Stream Stream)[] ?? multipleFiles.ToArray();
Exemplo n.º 9
0
        void UpdateImage()
        {
            var item = view.Collection [Item];

            string orig_path = item.DefaultVersion.Uri.LocalPath;

            var pixbuf = Utils.PixbufUtils.ShallowCopy(preview_cache.Get(orig_path + show_histogram));

            if (pixbuf == null)
            {
                // A bizarre pixbuf = hack to try to deal with cinematic displays, etc.
                int preview_size = ((Screen.Width + Screen.Height) / 2) / 3;
                try {
                    pixbuf = PhotoLoader.LoadAtMaxSize(item, preview_size, preview_size);
                } catch (Exception) {
                    pixbuf = null;
                }

                if (pixbuf != null)
                {
                    preview_cache.Add(orig_path + show_histogram, pixbuf);
                    AddHistogram(pixbuf);
                    image.Pixbuf = pixbuf;
                }
                else
                {
                    image.Pixbuf = PixbufUtils.ErrorPixbuf;
                }
            }
            else
            {
                image.Pixbuf = pixbuf;
                pixbuf.Dispose();
            }

            string desc = string.Empty;

            if (!string.IsNullOrEmpty(item.Description))
            {
                desc = item.Description + Environment.NewLine;
            }

            desc      += item.Time + "   " + item.Name;
            label.Text = desc;
        }
Exemplo n.º 10
0
 async void AddPhoto(object obj)
 {
     try
     {
         OpenFileDialog openFileDialog = new OpenFileDialog();
         openFileDialog.ShowDialog();
         var   path = openFileDialog.FileName;
         Photo c    = new Photo()
         {
             Id          = ++lastId,
             AddedDate   = DateTime.Now,
             ClientPhoto = File.ReadAllBytes(path)
         };
         Photos.Add(c);
         await PhotoLoader.AddPhoto(c);
     }
     catch { MessageBox.Show("Oops."); }
 }
Exemplo n.º 11
0
        public async Task <IActionResult> AddPhoto(int id, IFormFile photo)
        {
            if (photo == null)
            {
                return(BadRequest());
            }

            var film = await context.Films.FindAsync(id);

            if (film == null)
            {
                return(NotFound(id));
            }

            film.Logo = await PhotoLoader.addPhoto("film", photo, host.WebRootPath);

            await context.SaveChangesAsync();

            return(Ok());
        }
Exemplo n.º 12
0
 void Awake()
 {
     matrixes = new List<GameObject> ();
     loader = GameObject.Find ("PhotoLoader").GetComponent<PhotoLoader> ();
 }
Exemplo n.º 13
0
 void DeletePhoto(object obj)
 {
     Photos.Remove(obj as Photo);
     PhotoLoader.DeletePhoto(obj as Photo);
 }
Exemplo n.º 14
0
 public PhotosViewModel()
 {
     Photos = PhotoLoader.GetPhoto();
     Add    = new DelegateCommand(AddPhoto);
     Remove = new DelegateCommand(DeletePhoto);
 }
Exemplo n.º 15
0
 protected String GeneratePhotoUrl(Object fileName)
 {
     return(PhotoLoader.GenerateLinkForPhoto((String)fileName));
 }
Exemplo n.º 16
0
 void DeletePhoto(object obj)
 {
     //   var selectedPhoto = CollectionViewSource.GetDefaultView(photos).CurrentItem as Photo;
     Photos.Remove(obj as Photo);
     PhotoLoader.DeletePhoto(obj as Photo);
 }
 protected String GenerateFileName(Object thumbFileName)
 {
     return(PhotoLoader.GenerateLinkForPhoto((String)thumbFileName));
 }