From b736045b9b689dc32121de3548e7e3af9e96ad4e Mon Sep 17 00:00:00 2001 From: Wouter Huysentruit Date: Thu, 13 Jun 2024 08:37:27 +0200 Subject: [PATCH] Update ImageSharp to 2.1.x --- README.md | 3 +++ .../Barcoder.Renderer.Image.csproj | 6 +++--- .../Internal/EanContentRenderer.cs | 4 ++-- .../Barcoder.Renderer.Image.Tests.csproj | 2 +- tests/Barcoder.Renderer.Image.Tests/ImageRendererTests.cs | 8 ++++---- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 03ae2b2..f0b6e41 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,9 @@ Lightweight Barcode Encoding Library for .NET Framework, .NET Standard and .NET Core. Additional packages are available for rendering the generated barcode to SVG or an image. +Please note that the image renderer (`Barcoder.Renderer.Image`) requires .NET6 or .NET8 because of the dependency on `SixLabors.ImageSharp.Drawing` and no longer works for .NET Framework. +However, feel free to create your own renderer with another version or other image generation library. + Code ported from the GO project https://github.com/boombuler/barcode by [Florian Sundermann](https://github.com/boombuler). Supported Barcode Types: diff --git a/src/Barcoder.Renderer.Image/Barcoder.Renderer.Image.csproj b/src/Barcoder.Renderer.Image/Barcoder.Renderer.Image.csproj index 6790125..67b1368 100644 --- a/src/Barcoder.Renderer.Image/Barcoder.Renderer.Image.csproj +++ b/src/Barcoder.Renderer.Image/Barcoder.Renderer.Image.csproj @@ -1,9 +1,9 @@  - net472;netstandard2.0 + net6.0;net8.0 Barcoder.Renderer.Image - Image Renderer for Barcoder (.NET Framework, .NET Standard and .NET Core). + Image Renderer for Barcoder (.NET6, .NET8). true Wouter Huysentruit 1.0.0.0 @@ -16,7 +16,7 @@ - + diff --git a/src/Barcoder.Renderer.Image/Internal/EanContentRenderer.cs b/src/Barcoder.Renderer.Image/Internal/EanContentRenderer.cs index 1985ab0..ab35042 100644 --- a/src/Barcoder.Renderer.Image/Internal/EanContentRenderer.cs +++ b/src/Barcoder.Renderer.Image/Internal/EanContentRenderer.cs @@ -1,4 +1,4 @@ -using System.Numerics; +using System.Numerics; using SixLabors.Fonts; using SixLabors.ImageSharp; using SixLabors.ImageSharp.Drawing.Processing; @@ -68,7 +68,7 @@ private static void RenderWhiteRect(Image image, int x, int y, int width, in private static void RenderBlackText(Image image, string text, float x, float y, Font font) { - var options = new TextOptions(font) + var options = new RichTextOptions(font) { HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, diff --git a/tests/Barcoder.Renderer.Image.Tests/Barcoder.Renderer.Image.Tests.csproj b/tests/Barcoder.Renderer.Image.Tests/Barcoder.Renderer.Image.Tests.csproj index b2dc89d..dc9376a 100644 --- a/tests/Barcoder.Renderer.Image.Tests/Barcoder.Renderer.Image.Tests.csproj +++ b/tests/Barcoder.Renderer.Image.Tests/Barcoder.Renderer.Image.Tests.csproj @@ -10,7 +10,7 @@ - + all diff --git a/tests/Barcoder.Renderer.Image.Tests/ImageRendererTests.cs b/tests/Barcoder.Renderer.Image.Tests/ImageRendererTests.cs index 154438b..d1665c8 100644 --- a/tests/Barcoder.Renderer.Image.Tests/ImageRendererTests.cs +++ b/tests/Barcoder.Renderer.Image.Tests/ImageRendererTests.cs @@ -85,7 +85,7 @@ public void Render_ImageFormatBmp_ShouldRenderBmp() // Assert stream.Position = 0; - using var image = ImageSharp.Image.Load(stream, out IImageFormat imageFormat); + IImageFormat imageFormat = ImageSharp.Image.DetectFormat(stream); imageFormat.Name.Should().Be("BMP"); } @@ -102,7 +102,7 @@ public void Render_ImageFormatGif_ShouldRenderGif() // Assert stream.Position = 0; - using var image = ImageSharp.Image.Load(stream, out IImageFormat imageFormat); + IImageFormat imageFormat = ImageSharp.Image.DetectFormat(stream); imageFormat.Name.Should().Be("GIF"); } @@ -119,7 +119,7 @@ public void Render_ImageFormatJpeg_ShouldRenderJpeg() // Assert stream.Position = 0; - using var image = ImageSharp.Image.Load(stream, out IImageFormat imageFormat); + IImageFormat imageFormat = ImageSharp.Image.DetectFormat(stream); imageFormat.Name.Should().Be("JPEG"); } @@ -136,7 +136,7 @@ public void Render_ImageFormatPng_ShouldRenderPng() // Assert stream.Position = 0; - using var image = ImageSharp.Image.Load(stream, out IImageFormat imageFormat); + IImageFormat imageFormat = ImageSharp.Image.DetectFormat(stream); imageFormat.Name.Should().Be("PNG"); }