diff --git a/IronSoftware.Drawing/IronSoftware.Drawing.Common.Tests/UnitTests/AnyBitmapFunctionality.cs b/IronSoftware.Drawing/IronSoftware.Drawing.Common.Tests/UnitTests/AnyBitmapFunctionality.cs index 76a6671..18569bc 100644 --- a/IronSoftware.Drawing/IronSoftware.Drawing.Common.Tests/UnitTests/AnyBitmapFunctionality.cs +++ b/IronSoftware.Drawing/IronSoftware.Drawing.Common.Tests/UnitTests/AnyBitmapFunctionality.cs @@ -192,7 +192,7 @@ public void CastBitmap_to_AnyBitmap() bitmap.Save("expected.bmp"); anyBitmap.SaveAs("result.bmp"); - + anyBitmap.GetPixel(0, 0); //should not throw error AssertImageAreEqual("expected.bmp", "result.bmp", true); } @@ -217,7 +217,7 @@ public void CastImage_to_AnyBitmap() bitmap.Save("expected.bmp"); anyBitmap.SaveAs("result.bmp"); - + anyBitmap.GetPixel(0, 0); //should not throw error AssertImageAreEqual("expected.bmp", "result.bmp", true); } @@ -388,6 +388,22 @@ public void Clone_AnyBitmap() AssertImageAreEqual("expected.png", "result.png", true); } + [FactWithAutomaticDisplayName] + public void Clone_Crop_AnyBitmap() + { + string imagePath = GetRelativeFilePath("van-gogh-starry-night-vincent-van-gogh.jpg"); + var anyBitmap = AnyBitmap.FromFile(imagePath); + AnyBitmap clonedAnyBitmap = anyBitmap.Clone(new Rectangle(100,100,100,100)); + + clonedAnyBitmap.Width.Should().Be(100); + clonedAnyBitmap.Height.Should().Be(100); + + var recheckClonedAnyBitmap = AnyBitmap.FromBytes(clonedAnyBitmap.GetBytes()); + + recheckClonedAnyBitmap.Width.Should().Be(100); + recheckClonedAnyBitmap.Width.Should().Be(100); + } + [FactWithAutomaticDisplayName] public void CastSKBitmap_to_AnyBitmap() { @@ -397,7 +413,7 @@ public void CastSKBitmap_to_AnyBitmap() SaveSkiaBitmap(skBitmap, "expected.png"); anyBitmap.SaveAs("result.png"); - + anyBitmap.GetPixel(0, 0); //should not throw error AssertImageAreEqual("expected.png", "result.png", true); } @@ -430,7 +446,7 @@ public void CastSKImage_to_AnyBitmap() SaveSkiaImage(skImage, "expected.png"); anyBitmap.SaveAs("result.png"); - + anyBitmap.GetPixel(0, 0); //should not throw error AssertImageAreEqual("expected.png", "result.png", true); } @@ -463,7 +479,7 @@ public void CastSixLabors_to_AnyBitmap() imgSharp.Save("expected.bmp"); anyBitmap.SaveAs("result.bmp"); - + anyBitmap.GetPixel(0, 0); //should not throw error AssertImageAreEqual("expected.bmp", "result.bmp", true); } @@ -524,7 +540,7 @@ public void CastBitmap_to_AnyBitmap_using_FromBitmap() bitmap.Save("expected.png"); anyBitmap.SaveAs("result.png"); - + anyBitmap.GetPixel(0, 0); //should not throw error AssertImageAreEqual("expected.png", "result.png", true); } @@ -755,6 +771,7 @@ public void Should_Resize_Image(string fileName, int width, int height) var resizeAnyBitmap = new AnyBitmap(anyBitmap, width, height); _ = resizeAnyBitmap.Width.Should().Be(width); _ = resizeAnyBitmap.Height.Should().Be(height); + resizeAnyBitmap.GetPixel(0, 0); //should not throw error } [FactWithAutomaticDisplayName] @@ -936,7 +953,7 @@ public void CastMaui_to_AnyBitmap() SaveMauiImages(image, "expected.bmp"); anyBitmap.SaveAs("result.bmp"); - + anyBitmap.GetPixel(0, 0); //should not throw error AssertImageAreEqual("expected.bmp", "result.bmp", true); } @@ -948,7 +965,7 @@ public void CastMaui_from_AnyBitmap() anyBitmap.SaveAs("expected.bmp"); SaveMauiImages(image, "result.bmp"); - + anyBitmap.GetPixel(0, 0); //should not throw error AssertImageAreEqual("expected.bmp", "result.bmp", true); } #endif @@ -972,6 +989,7 @@ public void Create_New_Image_Instance() blankBitmap.Width.Should().Be(8); blankBitmap.Height.Should().Be(8); + blankBitmap.GetPixel(0, 0); //should not throw error } [FactWithAutomaticDisplayName] @@ -1070,7 +1088,7 @@ public void CastAnyBitmap_from_SixLabors() image.Save("expected.bmp"); anyBitmap.SaveAs("result.bmp"); - + anyBitmap.GetPixel(0, 0); //should not throw error AssertLargeImageAreEqual("expected.bmp", "result.bmp", true); } #endif diff --git a/IronSoftware.Drawing/IronSoftware.Drawing.Common/AnyBitmap.cs b/IronSoftware.Drawing/IronSoftware.Drawing.Common/AnyBitmap.cs index 9bb1b3c..433df54 100644 --- a/IronSoftware.Drawing/IronSoftware.Drawing.Common/AnyBitmap.cs +++ b/IronSoftware.Drawing/IronSoftware.Drawing.Common/AnyBitmap.cs @@ -224,7 +224,7 @@ public AnyBitmap Clone() public AnyBitmap Clone(Rectangle rectangle) { var cloned = GetInternalImages().Select(img => img.Clone(x => x.Crop(rectangle))); - return new AnyBitmap(Binary, cloned); + return new AnyBitmap(cloned); } /// @@ -3236,7 +3236,7 @@ private void LoadAndResizeImage(AnyBitmap original, int width, int height) _lazyImage = new Lazy>(() => { - using var image = Image.Load(Binary); + var image = Image.Load(Binary); image.Mutate(img => img.Resize(width, height)); //update Binary diff --git a/NuGet/IronSoftware.Drawing.nuspec b/NuGet/IronSoftware.Drawing.nuspec index c5b4921..818dd7b 100644 --- a/NuGet/IronSoftware.Drawing.nuspec +++ b/NuGet/IronSoftware.Drawing.nuspec @@ -40,7 +40,9 @@ 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. + - Optimizes AnyBitmap memory usage. + - Updates Color.FromName to align with System.Drawing. + - Adds support for RebeccaPurple color. 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