public async Task <CommandResult> SaveImage(IFormFile image) { var savingResult = await _imageSaver.SaveImage(image); if (!savingResult.IsSuccessful) { return(new CommandResult(savingResult.Error)); } var currentUser = _userCredentialsGetter.GetCuurentUser(); var photo = new ProfilePhoto { AddedAtUtc = DateTime.UtcNow, UserId = currentUser.UserId, FilePath = savingResult.Result.Path, AdditionalInformation = QueryString.Create(new Dictionary <string, string> { { "Name", savingResult.Result.Name.ToString() }, { "Version", "1" } }).ToUriComponent(), }; _profileRepo.Add(photo); await _profileRepo.SaveChangesAsync(); return(new CommandResult()); }
static void TimerTick(object state) { try { saver.SaveImage(retriever.GetImage(camera)); } catch (ImageUnavailableException ex) // Allow the caller to see that certain image attempts failed { System.Console.WriteLine(string.Concat("Image unavailable at ", DateTime.Now.ToString("yyyy-MMM-dd HH:mm:ss"))); } }
public async Task <CommandResult> AddPhotoToObject(int objectId, IFormFile image) { var authorizationResult = _authorizer.IsAuthorized(o => o.OfferedObjectId == objectId, (o) => o.OwnerLogin.User); if (!authorizationResult) { return(new CommandResult(new ErrorMessage { ErrorCode = "OBJECT.PHOTO.UNAUTHORIZED", Message = "You are not authorized to add a photo to this object", StatusCode = System.Net.HttpStatusCode.Unauthorized })); } var @object = _objectsRepo.Get(objectId); if (@object is null || @object.ObjectStatus != ObjectStatus.Available) { return(new CommandResult(new ErrorMessage { ErrorCode = "OBJECT.DOES.NOT.EXISTS", Message = "You are not authorized to add a photo to this object", StatusCode = System.Net.HttpStatusCode.Unauthorized })); } var savingResult = await _imageSaver.SaveImage(image); if (!savingResult.IsSuccessful) { return(new CommandResult(savingResult.Error)); } var newPhoto = new ObjectPhoto { AddedAtUtc = DateTime.UtcNow, ObjectId = objectId, AdditionalInformation = QueryString.Create(new Dictionary <string, string> { { "Name", savingResult.Result.Name.ToString() }, { "Version", "1" } }).ToUriComponent(), FilePath = savingResult.Result.Path, }; _photoRepo.Add(newPhoto); await _photoRepo.SaveChangesAsync(); return(new CommandResult()); }
public void Perform() { var dialog = new SaveFileDialog { CheckFileExists = false, InitialDirectory = @"C:\Users\Public\Pictures", DefaultExt = "png", FileName = "image.png", Filter = "Images |*.bmp|Images |*.jpg;*.jpeg|Images |*.png|Images |*.gif" }; var dialogResult = dialog.ShowDialog(); if (dialogResult == DialogResult.OK) { imageSaver.SaveImage(canvas, dialog.FileName); } }
public Result <None> CreateImage(IInitialSettings settings) { var words = reader.ReadWords(settings.InputFilePath); return(wordProcessor.ProcessWords(words) .Then(wordsWithCount => wordsWithCount.ToList()) .Then(wordsWithCount => { words = wordsWithCount.Select(e => e.Word); var sizes = converter.ConvertToSizes(wordsWithCount); var rectangles = layouter.GetRectangles(sizes); return imageSizeCalculator.CalculateImageSize(rectangles) .Then(calculatedSize => HandleSize(settings, calculatedSize)) .Then(imageSize => (rect: GetWordRectangles(words, rectangles, imageSize), imageSize)); }) .Then(x => visualizer.DrawImage(x.rect, x.imageSize)) .Then(image => saver.SaveImage(image, settings.OutputFilePath))); }
public void CreateImage(IInitialSettings settings) { var words = reader.ReadWords(settings.InputFilePath); var wordsWithCount = wordProcessor.ProcessWords(words).ToList(); var sizes = converter.ConvertToSizes(wordsWithCount); var rectangles = layouter.GetRectangles(sizes); var imageSize = settings.ImageSize; if (imageSize == Size.Empty) { imageSize = imageSizeCalculator.CalculateImageSize(rectangles); } rectangles = rectanglesTransformer.TransformRectangles(rectangles, imageSize); words = wordsWithCount.Select(e => e.Word); var wordRectangles = words.Zip(rectangles, (w, r) => new WordRectangle(w, r)).ToList(); var image = visualizer.DrawImage(wordRectangles, imageSize); saver.SaveImage(image, settings.OutputFilePath); }
public static void SaveImage(this Bitmap bitmap, IImageSaver saver, string filename) { saver.SaveImage(bitmap, filename); }
public Result <Bitmap> SaveImage(Bitmap image) => imageSaver.SaveImage(image, Settings.OutputPath);
public async Task <CommandResult <TagDto> > AddTag(AddTagDto tag) { if (tag is null) { return(new ErrorMessage { ErrorCode = "CATALOG.TAG.ADD.NULL", Message = "Please send a valid data", StatusCode = System.Net.HttpStatusCode.BadRequest }.ToCommand <TagDto>()); } if (tag.TagName.IsNullOrEmpty()) { return(new ErrorMessage { ErrorCode = "CATALOG.TAG.ADD.NAME.EMPTY", Message = "Please send a valid Tag name", StatusCode = System.Net.HttpStatusCode.BadRequest }.ToCommand <TagDto>()); } if (tag.Photo is null) { return(new ErrorMessage { ErrorCode = "CATALOG.TAG.ADD.PHOTO.EMPTY", Message = "Please send a valid photo", StatusCode = System.Net.HttpStatusCode.BadRequest }.ToCommand <TagDto>()); } var existedTags = from t in _tagsRepo.Table where t.Name == tag.TagName select t; if (existedTags.Any()) { return(new ErrorMessage { ErrorCode = "CATALOG.TAG.ADD.ALREADY.EXISTED", Message = "The tag you are trying to add is already existed.", StatusCode = System.Net.HttpStatusCode.BadRequest }.ToCommand <TagDto>()); } var imageSavingResult = await _imageSaver.SaveImage(tag.Photo); if (!imageSavingResult.IsSuccessful) { return(imageSavingResult.Error.ToCommand <TagDto>()); } var tagModel = new Tag { Photo = new TagPhoto { FilePath = imageSavingResult.Result.Path, AdditionalInformation = QueryString.Create(new Dictionary <string, string> { { "Name", imageSavingResult.Result.Name.ToString() }, { "Version", "1" } }).ToUriComponent(), AddedAtUtc = DateTime.UtcNow, }, Name = tag.TagName, Description = tag.Discreption, }; _tagsRepo.Add(tagModel); await _tagsRepo.SaveChangesAsync(); return(new CommandResult <TagDto>( new TagDto { Name = tagModel.Name, Id = tagModel.Id, PhotoUrl = _photoUrlConstructor.Construct(tagModel.Photo) })); }
/// <summary> /// Save an image to a user specified path/filename /// </summary> public void SaveAs() { // Save the image passing in the method that applies the edits and returns the image: _imageSaver.SaveImage(ApplyEdits()); }
private string SaveTagCloud(Image image, ImageFormat format) { return(imageSaver.SaveImage(image, format)); }
private void SaveImage(Bitmap image, string path) { saver.SaveImage(image, ImageFormat.Png, path); Console.WriteLine("Image was succefuly saved"); }