C# Bitmap Library to Replace System.Drawing.Com/mon in .NET
IronDrawing은 무료 오픈 소스이며, 대부분의 .NET 드로잉 라이브러리 형식을 지원합니다
IronDrawing은 Iron Software에서 처음 개발한 오픈 소스 라이브러리로, C# 소프트웨어 엔지니어가 Windows, macOS 및 Linux 플랫폼의 .NET 프로젝트에서 System.Drawing.Com/mon을 대체할 수 있도록 지원합니다.
그래픽, 이미지 및 글꼴을 지원하는 .NET 5, 6, 7 및 8용 클래스 라이브러리와 NuGet 패키지를 개발하는 것은 쉬워야 합니다.
IronDrawing은 지속적으로 발전하는 모든 새로운 .NET 5, 6, 7 및 8 그래픽 표준 간의 원활한 가교 역할을 하므로, 사용자는 자신이 선호하는 표준 하나만 대상으로 개발하면 됩니다.
"system.drawing.com/mon은 이 플랫폼에서 지원되지 않습니다" 예외를 방지하기 위한 기술적 단계
- Implement System.drawing.com/mon is not possible for .NET 6 and .NET 7 & 8 on Linux and macOS platforms
- 이러한 플랫폼에서 System.Drawing.Com/mon을 사용하면 예외 메시지가 발생합니다
- .NET 6의 경우 System.Drawing.EnableUnixSupport 런타임 구성을 true로 설정하십시오.
- .NET 7 및 8에서는 System.Drawing.Com/mon에 대한 지원이 더 이상 제공되지 않습니다.
- .NET 7에서 System.Drawing.Com/mon을 대체하기 위해 오픈소스 라이브러리 IronSoftware.System.Drawing을 사용하십시오.
문맥
Microsoft .NET Framework은 전 세계 수백만 명의 소프트웨어 개발자가 사용하는 다중 플랫폼, 호환성이 뛰어난 소프트웨어 프레임워크입니다. Microsoft는 System.Drawing.Com/mon이 Windows 플랫폼에서만 지원되는 중대한 변경 사항을 발표했습니다.
이는 System.Drawing.Com/mon을 사용하는 크로스 플랫폼 라이브러리를 유지 관리하는 .NET 라이브러리 개발자들에게 문제가 됩니다. Microsoft가 권장하는 조치에 따르면, Windows 이외의 사용자도 지원할 수 있도록 라이브러리를 재빌드해야 하기 때문입니다. 자원봉사자와 학계 연구자들은 새로 제안된 그래픽 라이브러리가 등장할 때마다 모든 NuGet 패키지와 클래스 라이브러리를 재구축해야 할 것으로 예상되며, 이는 기술적 부채를 초래하여 최신 .NET의 도입 속도를 늦출 것입니다.
결국, .NET을 사용할 때는 NuGet을 사용하게 됩니다.
NuGet 패키지 개발자들은 매일 우리가 직접 작성하려면 수천 시간이 걸릴 .NET 및 사전 패키지화된 코드를 발전시켜 우리 모두에게 큰 도움을 주고 있습니다.
이 호환성 변경 사항은 NuGet 개발을 지연시킬 것이며, .NET 개발자들이 의존하는 코드 라이브러리가 폐기되거나 더 이상 사용되지 않게 될 수 있습니다. 지금 바로 행동해야 합니다!
당사의 솔루션
기존 및 새로운 그래픽 라이브러리 간 변환을 지원하는 중간 그래픽 형식입니다.
클래스 라이브러리 개발자로서, 귀하의 공개 Bitmap, Color, Rectangle, Font 및 Size 입력 및 출력은 모든 새로운 표준을 지원하는 단일 유형으로만 지정할 수 있습니다. 내부적으로는 원하는 대로 진행하셔도 됩니다.
IronDrawing은 .NET Framework 4.62와 하위 호환되며, .NET 8을 포함한 모든 버전의 .NET을 지원합니다.
IronDrawing의 개발 및 출시로 Bitmap, Color, Rectangle, Font, Size와 같은 중요한 클래스에 대한 통일된 형식이 부재한 문제를 해결합니다. IronSoftware.Drawing는 System.Drawing, Microsoft.Maui, SkiaSharp 및 SixLabors에서 이러한 유형의 구현 간에 원활하게 변환해 줍니다. 이를 통해 개발자인 귀하는 라이브러리 내의 해당 클래스 인스턴스를 모두 일일이 교체할 필요가 없습니다.
예를 들어, System.Drawing.Bitmap를 사용하는 경우, 다음 유형으로의 암시적 변환 기능을 갖춘 IronDrawing의 AnyBitmap 클래스를 사용할 수 있습니다: System.Drawing.Bitmap, System.Drawing.Image, SkiaSharp.SKBitmap, SkiaSharp.SKImage, SixLabors.ImageSharp, Microsoft.Maui.Graphics.Platform.PlatformImage.
왜 무료로 이 작업을 하는가
Iron Software의 저희는 .NET의 발전을 중요하게 생각하며, .NET이 성장하고 성공하기를 바라는 오랜 경력의 시니어 .NET 개발자들로, 이러한 열정을 바탕으로 IronDrawing을 개발했습니다. .NET 7에서 볼 수 있듯이 .NET이 성장하고 진화하는 모습을 보는 것은 정말 기쁜 일입니다. 저희는 하루 종일 NuGet을 사용하며, 여러분도 마찬가지일 것이라고 확신합니다. 저희는 System.Drawing에서 벗어나 미래로 원활하게 전환할 수 있도록 지원하고 장려하고자 합니다.
우리는 모든 .NET 클래스 라이브러리 및 NuGet 개발이 더 쉬워져 NuGet 생태계가 지속적으로 번창하고, 모든 .NET 개발자가 혜택을 누릴 수 있기를 바랍니다.
IronSoftware.Drawing 기능
AnyBitmap: 범용 호환이 가능한 Bitmap 클래스.IronSoftware.Drawing.AnyBitmap과 다음 유형 간의 암시적 형 변환이 지원됩니다:System.Drawing.BitmapSystem.Drawing.ImageSkiaSharp.SKBitmapSkiaSharp.SKImageSixLabors.ImageSharpMicrosoft.Maui.Graphics.Platform.PlatformImage
- Color: 범용 호환 Color 클래스.
IronSoftware.Drawing.Co/lor와 다음 지원 유형 간의 암시적 형 변환:System.Drawing.Co/lorSkiaSharp.SKColorSixLabors.ImageSharp.Co/lorSixLabors.ImageSharp.PixelFormats
Rectangle: 범용 호환이 가능한 Rectangle 클래스.IronSoftware.Drawing.Rectangle과 다음 지원 유형 간의 암시적 형 변환:System.Drawing.RectangleSkiaSharp.SKRectSkiaSharp.SKRectISixLabors.ImageSharp.Rectangle
- Font: 범용 호환이 가능한 Font 클래스.
IronSoftware.Drawing.Font과 다음 지원 유형 간의 암시적 형 변환:System.Drawing.FontSkiaSharp.SKFontSixLabors.Fonts.Font
호환성
IronSoftware.Drawing은 다음 플랫폼과의 호환성을 지원합니다:
- .NET 8, .NET 7, .NET 6, .NET 5, .NET Core, .NET Standard 및 .NET Framework 4.62 이상
- Windows, macOS, Linux, Docker, Azure 및 AWS
설치
IronDrawing (IronSoftware.Drawing) NuGet Install-Package는 빠르고 간편합니다. 다음과 같이 패키지를 설치해 주십시오:
Install-Package IronSoftware.System.Drawing
또는 공식 NuGet 웹사이트에서 직접 다운로드하십시오.
설치가 완료되면 C# 코드 상단에 using IronSoftware.Drawing;를 추가하여 사용을 시작할 수 있습니다.
코드 예시
AnyBitmap 예시
:path=/static-assets/drawing/content-code-examples/get-started/anybitmap.cs
using IronSoftware.Drawing;
using System.IO;
using System.Drawing;
// Create a new AnyBitmap object from a file
// Replace "FILE_PATH" with the actual path of the image you want to process
var bitmap = AnyBitmap.FromFile("FILE_PATH");
// Save the AnyBitmap object as a JPEG file
bitmap.SaveAs("result.jpg");
// Export the AnyBitmap as a byte array
// This can be useful if you want to send the image data over a network or save it in a database
var bytes = bitmap.ExportBytes();
// Create a memory stream to export the AnyBitmap as a JPEG stream with 100% quality
using (var resultExport = new MemoryStream())
{
// This exports the image to the stream with the specified format and quality
bitmap.ExportStream(resultExport, AnyBitmap.ImageFormat.Jpeg, 100);
// Be sure to use 'using' or manually close the stream to release resources
}
// Casting between System.Drawing.Bitmap and IronSoftware.Drawing.AnyBitmap
// Load a System.Drawing.Bitmap from the same file
System.Drawing.Bitmap image = new System.Drawing.Bitmap("FILE_PATH");
// This is an implicit conversion from System.Drawing.Bitmap to IronSoftware.Drawing.AnyBitmap
// This step is necessary if you are working with System.Drawing.Bitmap and need to convert to IronSoftware.Drawing.AnyBitmap for processing
IronSoftware.Drawing.AnyBitmap anyBitmap = AnyBitmap.FromBitmap(image);
// Save the resulting AnyBitmap from casting as a PNG file
anyBitmap.SaveAs("result-from-casting.png");
Imports IronSoftware.Drawing
Imports System.IO
Imports System.Drawing
' Create a new AnyBitmap object from a file
' Replace "FILE_PATH" with the actual path of the image you want to process
Private bitmap = AnyBitmap.FromFile("FILE_PATH")
' Save the AnyBitmap object as a JPEG file
bitmap.SaveAs("result.jpg")
' Export the AnyBitmap as a byte array
' This can be useful if you want to send the image data over a network or save it in a database
Dim bytes = bitmap.ExportBytes()
' Create a memory stream to export the AnyBitmap as a JPEG stream with 100% quality
Using resultExport = New MemoryStream()
' This exports the image to the stream with the specified format and quality
bitmap.ExportStream(resultExport, AnyBitmap.ImageFormat.Jpeg, 100)
' Be sure to use 'using' or manually close the stream to release resources
End Using
' Casting between System.Drawing.Bitmap and IronSoftware.Drawing.AnyBitmap
' Load a System.Drawing.Bitmap from the same file
Dim image As New System.Drawing.Bitmap("FILE_PATH")
' This is an implicit conversion from System.Drawing.Bitmap to IronSoftware.Drawing.AnyBitmap
' This step is necessary if you are working with System.Drawing.Bitmap and need to convert to IronSoftware.Drawing.AnyBitmap for processing
Dim anyBitmap As IronSoftware.Drawing.AnyBitmap = AnyBitmap.FromBitmap(image)
' Save the resulting AnyBitmap from casting as a PNG file
anyBitmap.SaveAs("result-from-casting.png")
색상 예시
:path=/static-assets/drawing/content-code-examples/get-started/color.cs
using IronSoftware.Drawing;
using System;
// The IronSoftware.Drawing library provides enhanced color manipulation features.
// This example demonstrates creating color objects and converting between
// System.Drawing.Color and IronSoftware.Drawing.Color.
// Create a new Color object from a hex string.
Color fromHex = Color.FromHex("#191919");
// Create a new Color object from RGB values.
Color fromRgb = Color.FromRgb(255, 255, 0);
// Create a new Color object using an enumeration.
Color fromEnum = Color.Crimson;
// Casting between System.Drawing.Color and IronSoftware.Drawing.Color.
System.Drawing.Color drawingColor = System.Drawing.Color.Red;
// Convert System.Drawing.Color to IronSoftware.Drawing.Color.
IronSoftware.Drawing.Color ironColor = Color.FromSystemColor(drawingColor);
// Access the alpha, red, green, and blue components of the IronSoftware.Drawing.Color.
byte alpha = ironColor.A;
byte red = ironColor.R;
byte green = ironColor.G;
byte blue = ironColor.B;
// Calculate the luminance of the color.
// Luminance is a value from 0 (black) to 100 (white) where 50 is the perceptual "middle grey".
double luminance = ironColor.GetLuminance();
// Log the calculated attributes to the console.
Console.WriteLine($"Color Details - ARGB: ({alpha}, {red}, {green}, {blue}), Luminance: {luminance}");
Imports IronSoftware.Drawing
Imports System
' The IronSoftware.Drawing library provides enhanced color manipulation features.
' This example demonstrates creating color objects and converting between
' System.Drawing.Color and IronSoftware.Drawing.Color.
' Create a new Color object from a hex string.
Private fromHex As Color = Color.FromHex("#191919")
' Create a new Color object from RGB values.
Private fromRgb As Color = Color.FromRgb(255, 255, 0)
' Create a new Color object using an enumeration.
Private fromEnum As Color = Color.Crimson
' Casting between System.Drawing.Color and IronSoftware.Drawing.Color.
Private drawingColor As System.Drawing.Color = System.Drawing.Color.Red
' Convert System.Drawing.Color to IronSoftware.Drawing.Color.
Private ironColor As IronSoftware.Drawing.Color = Color.FromSystemColor(drawingColor)
' Access the alpha, red, green, and blue components of the IronSoftware.Drawing.Color.
Private alpha As Byte = ironColor.A
Private red As Byte = ironColor.R
Private green As Byte = ironColor.G
Private blue As Byte = ironColor.B
' Calculate the luminance of the color.
' Luminance is a value from 0 (black) to 100 (white) where 50 is the perceptual "middle grey".
Private luminance As Double = ironColor.GetLuminance()
' Log the calculated attributes to the console.
Console.WriteLine($"Color Details - ARGB: ({alpha}, {red}, {green}, {blue}), Luminance: {luminance}")
사각형 예시
:path=/static-assets/drawing/content-code-examples/get-started/rectangle.cs
using IronSoftware.Drawing;
using System.Drawing;
// Declare an IronSoftware.Drawing.Rectangle object
IronSoftware.Drawing.Rectangle ironRectangle = new IronSoftware.Drawing.Rectangle(5, 5, 50, 50);
// Declare a System.Drawing.Rectangle object
System.Drawing.Rectangle systemRectangle = new System.Drawing.Rectangle(10, 10, 150, 150);
// Implicitly convert System.Drawing.Rectangle to IronSoftware.Drawing.Rectangle
// Note: Uncomment and use appropriate conversion methods if available in the IronSoftware.Drawing library
// ironRectangle = (IronSoftware.Drawing.Rectangle)systemRectangle;
// Output the properties of IronSoftware.Drawing.Rectangle if conversion is successful
// These Console.WriteLine statements assume this code runs in a console environment
Console.WriteLine(ironRectangle.X);
Console.WriteLine(ironRectangle.Y);
Console.WriteLine(ironRectangle.Width);
Console.WriteLine(ironRectangle.Height);
Imports IronSoftware.Drawing
Imports System.Drawing
' Declare an IronSoftware.Drawing.Rectangle object
Private ironRectangle As New IronSoftware.Drawing.Rectangle(5, 5, 50, 50)
' Declare a System.Drawing.Rectangle object
Private systemRectangle As New System.Drawing.Rectangle(10, 10, 150, 150)
' Implicitly convert System.Drawing.Rectangle to IronSoftware.Drawing.Rectangle
' Note: Uncomment and use appropriate conversion methods if available in the IronSoftware.Drawing library
' ironRectangle = (IronSoftware.Drawing.Rectangle)systemRectangle;
' Output the properties of IronSoftware.Drawing.Rectangle if conversion is successful
' These Console.WriteLine statements assume this code runs in a console environment
Console.WriteLine(ironRectangle.X)
Console.WriteLine(ironRectangle.Y)
Console.WriteLine(ironRectangle.Width)
Console.WriteLine(ironRectangle.Height)
글꼴 예시
:path=/static-assets/drawing/content-code-examples/get-started/font.cs
using System;
using System.Drawing;
using IronSoftware.Drawing;
// Create a new Font object with a specified font family, style, and size
IronSoftware.Drawing.Font font = new IronSoftware.Drawing.Font("Times New Roman", FontStyle.Italic | FontStyle.Bold, 30);
// Create a new instance of System.Drawing.Font
System.Drawing.Font drawingFont = new System.Drawing.Font("Courier New", 30);
try
{
// Attempt to cast System.Drawing.Font to IronSoftware.Drawing.Font
// Note: This cast may not be directly possible if the libraries do not support each other;
// additional conversion logic might be required.
IronSoftware.Drawing.Font ironFont = new IronSoftware.Drawing.Font(drawingFont.FontFamily.Name, drawingFont.Style, drawingFont.Size);
// Accessing properties of the IronSoftware.Drawing.Font object
string familyName = ironFont.FamilyName; // Get the font family name
FontStyle style = ironFont.Style; // Get the combined font style (italic, bold, etc.)
float size = ironFont.Size; // Get the font size
bool isItalic = ironFont.Italic; // Determine if the font style includes Italic
bool isBold = ironFont.Bold; // Determine if the font style includes Bold
// Output the font properties to verify correctness
Console.WriteLine($"Family: {familyName}, Style: {style}, Size: {size}, Italic: {isItalic}, Bold: {isBold}");
}
catch (InvalidCastException)
{
Console.WriteLine("The conversion between System.Drawing.Font and IronSoftware.Drawing.Font is not directly supported.");
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
Imports System
Imports System.Drawing
Imports IronSoftware.Drawing
' Create a new Font object with a specified font family, style, and size
Private font As New IronSoftware.Drawing.Font("Times New Roman", FontStyle.Italic Or FontStyle.Bold, 30)
' Create a new instance of System.Drawing.Font
Private drawingFont As New System.Drawing.Font("Courier New", 30)
Try
' Attempt to cast System.Drawing.Font to IronSoftware.Drawing.Font
' Note: This cast may not be directly possible if the libraries do not support each other;
' additional conversion logic might be required.
Dim ironFont As New IronSoftware.Drawing.Font(drawingFont.FontFamily.Name, drawingFont.Style, drawingFont.Size)
' Accessing properties of the IronSoftware.Drawing.Font object
Dim familyName As String = ironFont.FamilyName ' Get the font family name
Dim style As FontStyle = ironFont.Style ' Get the combined font style (italic, bold, etc.)
Dim size As Single = ironFont.Size ' Get the font size
Dim isItalic As Boolean = ironFont.Italic ' Determine if the font style includes Italic
Dim isBold As Boolean = ironFont.Bold ' Determine if the font style includes Bold
' Output the font properties to verify correctness
Console.WriteLine($"Family: {familyName}, Style: {style}, Size: {size}, Italic: {isItalic}, Bold: {isBold}")
Catch e1 As InvalidCastException
Console.WriteLine("The conversion between System.Drawing.Font and IronSoftware.Drawing.Font is not directly supported.")
Catch ex As Exception
Console.WriteLine($"An error occurred: {ex.Message}")
End Try
지원 가능
라이선스
라이선스 정보는 다음에서 확인할 수 있습니다: LICENSE.txt
기여하기
IronDrawing 오픈소스 프로젝트에 기여하고 싶으시다면, GitHub 저장소에 풀 리퀘스트를 보내기 전에 라이선스를 읽어보시기 바랍니다.
정보
Iron Software에 대한 자세한 내용은 당사 웹사이트를 방문해 주십시오: https://ironsoftware.com/
Iron Software의 지원
일반적인 지원 및 기술 문의는 다음 이메일 주소로 보내주십시오: mailto:support@ironsoftware.com/mailto:support@ironsoftware.com
