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}"); } }
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}"); } }
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."); } }
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(); } }