From 5e89ceed75359f63ab2a5c2b157c0b98892655af Mon Sep 17 00:00:00 2001 From: first-ironsoftware Date: Tue, 20 May 2025 16:53:46 +0700 Subject: [PATCH 1/3] Update SixLabors.ImageSharp version --- .../IronSoftware.Drawing.Common.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/IronSoftware.Drawing/IronSoftware.Drawing.Common/IronSoftware.Drawing.Common.csproj b/IronSoftware.Drawing/IronSoftware.Drawing.Common/IronSoftware.Drawing.Common.csproj index ec774df..ef6c50a 100644 --- a/IronSoftware.Drawing/IronSoftware.Drawing.Common/IronSoftware.Drawing.Common.csproj +++ b/IronSoftware.Drawing/IronSoftware.Drawing.Common/IronSoftware.Drawing.Common.csproj @@ -35,8 +35,8 @@ - - + + From d84fd0c8155bb8559ca981755ccaabf9c1d4d39c Mon Sep 17 00:00:00 2001 From: first-ironsoftware Date: Tue, 20 May 2025 16:58:03 +0700 Subject: [PATCH 2/3] Update release notes --- NuGet/IronSoftware.Drawing.nuspec | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NuGet/IronSoftware.Drawing.nuspec b/NuGet/IronSoftware.Drawing.nuspec index 0946583..7183b4e 100644 --- a/NuGet/IronSoftware.Drawing.nuspec +++ b/NuGet/IronSoftware.Drawing.nuspec @@ -40,7 +40,8 @@ Supports: For general support and technical inquiries, please email us at: support@ironsoftware.com IronSoftware.System.Drawing is an open-source solution for .NET developers to replace System.Drawing.Common with a universal and flexible library. - Updates internal dependencies. - - Disable warning messages from BitMiracle.LibTiff.NET. + - Fixes the issue of some images are auto-rotated when loading as AnyBitmap. + - Adds an option called preserveOriginalFormat to download input image as Rgba32 via AnyBitmap. Copyright © Iron Software 2022-2025 Images, Bitmap, SkiaSharp, SixLabors, BitMiracle, Maui, SVG, TIFF, TIF, GIF, JPEG, PNG, Color, Rectangle, Drawing, C#, VB.NET, ASPX, create, render, generate, standard, netstandard2.0, core, netcore From 0cf5bf4d8ab6e9a33f6bfbc788b3dd8dcd99fde1 Mon Sep 17 00:00:00 2001 From: Meee Date: Mon, 26 May 2025 16:31:53 +0700 Subject: [PATCH 3/3] Overloads AnyBitmap constructors and From methods Provides overloaded constructors and From methods for AnyBitmap, allowing to omit the preserveOriginalFormat parameter. The default value for preserveOriginalFormat is true. This change maintains backwards compatibility while simplifying the API for common use cases. --- .../IronSoftware.Drawing.Common/AnyBitmap.cs | 253 ++++++++++++++---- 1 file changed, 208 insertions(+), 45 deletions(-) diff --git a/IronSoftware.Drawing/IronSoftware.Drawing.Common/AnyBitmap.cs b/IronSoftware.Drawing/IronSoftware.Drawing.Common/AnyBitmap.cs index 5f3a22d..6a756a6 100644 --- a/IronSoftware.Drawing/IronSoftware.Drawing.Common/AnyBitmap.cs +++ b/IronSoftware.Drawing/IronSoftware.Drawing.Common/AnyBitmap.cs @@ -463,9 +463,17 @@ public T ToBitmap() /// Create a new Bitmap from a a Byte Span. /// /// A Byte Span of image data in any common format. - /// Determine whether to load as its original pixel format or Rgba32. - /// Default is true. Set to false to load as Rgba32. - public static AnyBitmap FromSpan(ReadOnlySpan span, bool preserveOriginalFormat = true) + public static AnyBitmap FromSpan(ReadOnlySpan span) + { + return new AnyBitmap(span, true); + } + + /// + /// Create a new Bitmap from a a Byte Span. + /// + /// A Byte Span of image data in any common format. + /// Determine whether to load as its original pixel format or Rgba32. + public static AnyBitmap FromSpan(ReadOnlySpan span, bool preserveOriginalFormat) { return new AnyBitmap(span, preserveOriginalFormat); } @@ -474,9 +482,17 @@ public static AnyBitmap FromSpan(ReadOnlySpan span, bool preserveOriginalF /// Create a new Bitmap from a a Byte Array. /// /// A ByteArray of image data in any common format. - /// Determine whether to load as its original pixel format or Rgba32. - /// Default is true. Set to false to load as Rgba32. - public static AnyBitmap FromBytes(byte[] bytes, bool preserveOriginalFormat = true) + public static AnyBitmap FromBytes(byte[] bytes) + { + return new AnyBitmap(bytes, true); + } + + /// + /// Create a new Bitmap from a a Byte Array. + /// + /// A ByteArray of image data in any common format. + /// Determine whether to load as its original pixel format or Rgba32. + public static AnyBitmap FromBytes(byte[] bytes, bool preserveOriginalFormat) { return new AnyBitmap(bytes, preserveOriginalFormat); } @@ -484,12 +500,23 @@ public static AnyBitmap FromBytes(byte[] bytes, bool preserveOriginalFormat = tr /// /// Create a new Bitmap from a (bytes). /// - /// A of image data in any common format. - /// Determine whether to load as its original pixel format or Rgba32. + /// A of image data in any common format. /// Default is true. Set to false to load as Rgba32. /// /// - public static AnyBitmap FromStream(MemoryStream stream, bool preserveOriginalFormat = true) + public static AnyBitmap FromStream(MemoryStream stream) + { + return new AnyBitmap(stream, true); + } + + /// + /// Create a new Bitmap from a (bytes). + /// + /// A of image data in any common format. + /// Determine whether to load as its original pixel format or Rgba32. + /// + /// + public static AnyBitmap FromStream(MemoryStream stream, bool preserveOriginalFormat) { return new AnyBitmap(stream, preserveOriginalFormat); } @@ -498,11 +525,21 @@ public static AnyBitmap FromStream(MemoryStream stream, bool preserveOriginalFor /// Create a new Bitmap from a (bytes). /// /// A of image data in any common format. - /// Determine whether to load as its original pixel format or Rgba32. - /// Default is true. Set to false to load as Rgba32. /// /// - public static AnyBitmap FromStream(Stream stream, bool preserveOriginalFormat = true) + public static AnyBitmap FromStream(Stream stream) + { + return new AnyBitmap(stream, true); + } + + /// + /// Create a new Bitmap from a (bytes). + /// + /// A of image data in any common format. + /// Determine whether to load as its original pixel format or Rgba32. + /// + /// + public static AnyBitmap FromStream(Stream stream, bool preserveOriginalFormat) { return new AnyBitmap(stream, preserveOriginalFormat); } @@ -511,10 +548,19 @@ public static AnyBitmap FromStream(Stream stream, bool preserveOriginalFormat = /// Construct a new Bitmap from binary data (byte span). /// /// A byte span of image data in any common format. - /// Determine whether to load as its original pixel format or Rgba32. - /// Default is true. Set to false to load as Rgba32. /// - public AnyBitmap(ReadOnlySpan span, bool preserveOriginalFormat = true) + public AnyBitmap(ReadOnlySpan span) + { + LoadImage(span, true); + } + + /// + /// Construct a new Bitmap from binary data (byte span). + /// + /// A byte span of image data in any common format. + /// Determine whether to load as its original pixel format or Rgba32. + /// + public AnyBitmap(ReadOnlySpan span, bool preserveOriginalFormat) { LoadImage(span, preserveOriginalFormat); } @@ -523,11 +569,21 @@ public AnyBitmap(ReadOnlySpan span, bool preserveOriginalFormat = true) /// Construct a new Bitmap from binary data (bytes). /// /// A ByteArray of image data in any common format. - /// Determine whether to load as its original pixel format or Rgba32. - /// Default is true. Set to false to load as Rgba32. - /// + /// + /// + public AnyBitmap(byte[] bytes) + { + LoadImage(bytes, true); + } + + /// + /// Construct a new Bitmap from binary data (bytes). + /// + /// A ByteArray of image data in any common format. + /// Determine whether to load as its original pixel format or Rgba32. + /// /// - public AnyBitmap(byte[] bytes, bool preserveOriginalFormat = true) + public AnyBitmap(byte[] bytes, bool preserveOriginalFormat) { LoadImage(bytes, preserveOriginalFormat); } @@ -536,8 +592,18 @@ public AnyBitmap(byte[] bytes, bool preserveOriginalFormat = true) /// Construct a new Bitmap from a (bytes). /// /// A of image data in any common format. - /// Determine whether to load as its original pixel format or Rgba32. - /// Default is true. Set to false to load as Rgba32. + /// + /// + public AnyBitmap(MemoryStream stream) + { + LoadImage(stream.ToArray(), true); + } + + /// + /// Construct a new Bitmap from a (bytes). + /// + /// A of image data in any common format. + /// Determine whether to load as its original pixel format or Rgba32. /// /// public AnyBitmap(MemoryStream stream, bool preserveOriginalFormat = true) @@ -549,11 +615,21 @@ public AnyBitmap(MemoryStream stream, bool preserveOriginalFormat = true) /// Construct a new Bitmap from a (bytes). /// /// A of image data in any common format. - /// Determine whether to load as its original pixel format or Rgba32. - /// Default is true. Set to false to load as Rgba32. /// /// - public AnyBitmap(Stream stream, bool preserveOriginalFormat = true) + public AnyBitmap(Stream stream) + { + LoadImage(stream, true); + } + + /// + /// Construct a new Bitmap from a (bytes). + /// + /// A of image data in any common format. + /// Determine whether to load as its original pixel format or Rgba32. + /// + /// + public AnyBitmap(Stream stream, bool preserveOriginalFormat) { LoadImage(stream, preserveOriginalFormat); } @@ -574,11 +650,21 @@ public AnyBitmap(AnyBitmap original, int width, int height) /// Construct a new Bitmap from a file. /// /// A fully qualified file path./ - /// Determine whether to load as its original pixel format or Rgba32. - /// Default is true. Set to false to load as Rgba32. - /// + /// /// - public AnyBitmap(string file, bool preserveOriginalFormat = true) + public AnyBitmap(string file) + { + LoadImage(File.ReadAllBytes(file), true); + } + + /// + /// Construct a new Bitmap from a file. + /// + /// A fully qualified file path./ + /// Determine whether to load as its original pixel format or Rgba32. + /// + /// + public AnyBitmap(string file, bool preserveOriginalFormat) { LoadImage(File.ReadAllBytes(file), preserveOriginalFormat); } @@ -587,11 +673,29 @@ public AnyBitmap(string file, bool preserveOriginalFormat = true) /// Construct a new Bitmap from a Uri /// /// The uri of the image. - /// Determine whether to load as its original pixel format or Rgba32. - /// Default is true. Set to false to load as Rgba32. - /// + /// /// - public AnyBitmap(Uri uri, bool preserveOriginalFormat = true) + public AnyBitmap(Uri uri) + { + try + { + using Stream stream = LoadUriAsync(uri).GetAwaiter().GetResult(); + LoadImage(stream, true); + } + catch (Exception e) + { + throw new NotSupportedException("Error while loading AnyBitmap from Uri", e); + } + } + + /// + /// Construct a new Bitmap from a Uri + /// + /// The uri of the image. + /// Determine whether to load as its original pixel format or Rgba32. + /// + /// + public AnyBitmap(Uri uri, bool preserveOriginalFormat) { try { @@ -619,11 +723,28 @@ public AnyBitmap(int width, int height, Color backgroundColor = null) /// Create a new Bitmap from a file. /// /// A fully qualified file path. - /// Determine whether to load as its original pixel format or Rgba32. - /// Default is true. Set to false to load as Rgba32. - /// + /// /// - public static AnyBitmap FromFile(string file, bool preserveOriginalFormat = true) + public static AnyBitmap FromFile(string file) + { + if (file.ToLower().EndsWith(".svg")) + { + return LoadSVGImage(file, true); + } + else + { + return new AnyBitmap(file, true); + } + } + + /// + /// Create a new Bitmap from a file. + /// + /// A fully qualified file path. + /// Determine whether to load as its original pixel format or Rgba32. + /// + /// + public static AnyBitmap FromFile(string file, bool preserveOriginalFormat) { if (file.ToLower().EndsWith(".svg")) { @@ -639,13 +760,33 @@ public static AnyBitmap FromFile(string file, bool preserveOriginalFormat = true /// Construct a new Bitmap from a Uri /// /// The uri of the image. - /// Determine whether to load as its original pixel format or Rgba32. - /// Default is true. Set to false to load as Rgba32. /// /// - /// - /// - public static async Task FromUriAsync(Uri uri, bool preserveOriginalFormat = true) + /// + /// + public static async Task FromUriAsync(Uri uri) + { + try + { + using Stream stream = await LoadUriAsync(uri); + return new AnyBitmap(stream, true); + } + catch (Exception e) + { + throw new NotSupportedException("Error while loading AnyBitmap from Uri", e); + } + } + + /// + /// Construct a new Bitmap from a Uri + /// + /// The uri of the image. + /// Determine whether to load as its original pixel format or Rgba32. + /// + /// + /// + /// + public static async Task FromUriAsync(Uri uri, bool preserveOriginalFormat) { try { @@ -662,15 +803,13 @@ public static async Task FromUriAsync(Uri uri, bool preserveOriginalF /// Construct a new Bitmap from a Uri /// /// The uri of the image. - /// Determine whether to load as its original pixel format or Rgba32. - /// Default is true. Set to false to load as Rgba32. /// /// - /// + /// #if NET6_0_OR_GREATER [Obsolete("FromUri(Uri) is obsolete for net60 or greater because it uses WebClient which is obsolete. Consider using FromUriAsync(Uri) method.")] #endif - public static AnyBitmap FromUri(Uri uri, bool preserveOriginalFormat = true) + public static AnyBitmap FromUri(Uri uri) { try { @@ -683,6 +822,30 @@ public static AnyBitmap FromUri(Uri uri, bool preserveOriginalFormat = true) } } + /// + /// Construct a new Bitmap from a Uri + /// + /// The uri of the image. + /// Determine whether to load as its original pixel format or Rgba32. + /// + /// + /// +#if NET6_0_OR_GREATER + [Obsolete("FromUri(Uri) is obsolete for net60 or greater because it uses WebClient which is obsolete. Consider using FromUriAsync(Uri) method.")] +#endif + public static AnyBitmap FromUri(Uri uri, bool preserveOriginalFormat) + { + try + { + using WebClient client = new(); + return new AnyBitmap(client.OpenRead(uri), preserveOriginalFormat); + } + catch (Exception e) + { + throw new NotSupportedException("Error while loading AnyBitmap from Uri", e); + } + } + /// /// Creates an AnyBitmap object from a buffer of RGB pixel data. ///