From 87e43acdaadbf5cd8f184dcdc10a44ebce1f2b55 Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Sun, 18 Jun 2017 12:48:16 +0100 Subject: [PATCH] impove sample --- samples/AvatarWithRoundedCorner/Program.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/samples/AvatarWithRoundedCorner/Program.cs b/samples/AvatarWithRoundedCorner/Program.cs index 56b30744c..5516a73fb 100644 --- a/samples/AvatarWithRoundedCorner/Program.cs +++ b/samples/AvatarWithRoundedCorner/Program.cs @@ -11,18 +11,25 @@ namespace AvatarWithRoundedCorner { static void Main(string[] args) { - - using (var image = Image.Load("fb.jpg")) + System.IO.Directory.CreateDirectory("output"); + + GenerateAvatar("fb.jpg", "output/fb.png", new ImageSharp.Size(200, 200), 20); + GenerateAvatar("fb.jpg", "output/fb-round.png", new ImageSharp.Size(200, 200), 100); + GenerateAvatar("fb.jpg", "output/fb-rounder.png", new ImageSharp.Size(200, 200), 150); + } + + private static void GenerateAvatar(string source, string destination, ImageSharp.Size size, float cornerRadius) + { + using (var image = Image.Load(source)) { image.Resize(new ImageSharp.Processing.ResizeOptions { - Size = new ImageSharp.Size(200, 200), + Size = size, Mode = ImageSharp.Processing.ResizeMode.Crop }); - ApplyRoundedCourners(image, 30); - System.IO.Directory.CreateDirectory("output"); - image.Save("output/fb.png"); + ApplyRoundedCourners(image, cornerRadius); + image.Save(destination); } }