Implemented buffer/stream constructors for CanvasImage (#246)

* Implemented buffer/stream constructors for CanvasImage and added section to Canvas example

Signed-off-by: David Butler <mail@davidbutlerdesign.co.uk>
This commit is contained in:
David Butler
2021-01-27 17:12:22 +00:00
committed by GitHub
parent ad49b6aa67
commit 953008b5e3
3 changed files with 33 additions and 2 deletions

View File

@ -14,9 +14,9 @@
</ItemGroup>
<ItemGroup>
<None Update="cake.png">
<EmbeddedResource Include="cake.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</EmbeddedResource>
</ItemGroup>
</Project>

View File

@ -1,3 +1,5 @@
using System.Diagnostics;
using System.Reflection;
using SixLabors.ImageSharp.Processing;
using Spectre.Console;
using Spectre.Console.Rendering;
@ -23,6 +25,16 @@ namespace CanvasExample
image.NoMaxWidth();
image.Mutate(ctx => ctx.Grayscale().Rotate(-45).EntropyCrop());
Render(image, "Image from file (fit, greyscale, rotated)");
// Draw image again, but load from embedded resource rather than file
using (var fileStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Canvas.cake.png"))
{
Debug.Assert(fileStream != null);
var embeddedImage = new CanvasImage(fileStream);
embeddedImage.BilinearResampler();
embeddedImage.MaxWidth(16);
Render(embeddedImage, "Image from embedded resource (16 wide)");
}
}
private static void Render(IRenderable canvas, string title)