private void GenerateThumbnail(WallpaperFileImage original) { var fileContent = _wallpaperManager.GetFile(_wallpaper, original); if (!fileContent.HasValue) { return; } using (var image = Image.Load(fileContent.Value.Data)) using (var destStream = new MemoryStream()) { const int targetHeight = 300; var ratio = image.Size().Height / targetHeight; var targetSize = new Size(image.Size().Width / ratio, targetHeight); image.Mutate(x => x.Resize(new ResizeOptions { Size = targetSize })); image.SaveAsPng(destStream); var file = new WallpaperFileWithData() { Data = destStream.ToArray(), FileDto = new WallpaperFileThumbnail { OriginalFileId = original.FileId, Height = targetSize.Height, Width = targetSize.Width } }; _wallpaperManager.AddFile(_wallpaper, file); } }
public void Deploy(Plugin.Application.Wallpaper.Common.Model.Wallpaper wallpaper) { var deployFolder = GetFolder(); foreach (var file in wallpaper.Files) { var data = _wallpaperManager.GetFile(wallpaper, file); if (data.HasValue) { var fileInfo = new FileInfo(Path.Combine(deployFolder.FullName, wallpaper.Id + "_" + file.FileId + ".jpg")); if (fileInfo.Exists) { continue; } using (var stream = fileInfo.OpenWrite()) { stream.Write(data.Value.Data, 0, data.Value.Data.Length); } } } }