C# Bitmap Library to Replace System.Drawing.Common in .NET

This article was translated from English: Does it need improvement?
Translated
View the article in English

IronDrawing은 무료 오픈 소스 소프트웨어이며 대부분의 .NET 드로잉 라이브러리 형식을 지원합니다.

IronDrawing은 Iron Software가 원래 개발한 오픈 소스 라이브러리로, C# 소프트웨어 엔지니어들이 Windows, macOS, 그리고 Linux 플랫폼의 .NET 프로젝트에서 System.Drawing.Common를 대체할 수 있도록 도와줍니다.

.NET 5, 6, 7 및 8용 그래픽, 이미지 및 글꼴을 지원하는 클래스 라이브러리와 NuGet 패키지를 개발하는 것은 쉬워야 합니다.

IronDrawing은 새롭게 제안된 .NET 5, 6, 7 및 8 그래픽 표준이 발전함에 따라 이 모든 표준 간의 원활한 연결 고리 역할을 하므로 원하는 표준 에 대해서만 개발하면 됩니다.

IronDrawing은 무료 오픈 소스 소프트웨어이며 대부분의 .NET 드로잉 라이브러리 형식을 지원합니다.

문맥

Microsoft .NET 은 전 세계 수백만 명의 소프트웨어 개발자가 사용하는 다중 플랫폼 호환성이 뛰어난 소프트웨어 프레임워크입니다. Microsoft는 System.Drawing.Common가 Windows 플랫폼에서만 지원되도록 하는 중대한 변경 사항발표했습니다.

.NET 라이브러리 개발자들은 System.Drawing.Common를 사용하는 크로스 플랫폼 라이브러리를 유지관리하기 때문에 문제가 발생하며, Microsoft's 권장 조치는 비-Windows 사용자를 지원하도록 라이브러리를 재구축할 것을 요구합니다. 자원봉사자와 학자들은 새롭게 제안된 그래픽 라이브러리가 등장할 때마다 이를 사용하기 위해 모든 NuGet 패키지와 클래스 라이브러리를 재구축해야 하므로 기술적 부채가 발생하여 최신 .NET 의 도입이 늦어질 것입니다.

궁극적으로 우리는 .NET 사용할 때 NuGet 사용합니다.

NuGet 패키지 개발자들은 .NET 발전시키고 미리 패키지화된 코드를 제공함으로써 우리 모두에게 큰 도움을 주고 있습니다. 우리가 직접 코드를 작성하려면 매일 수천 시간이 걸릴 것입니다.

이번 호환성 파괴 변경으로 인해 NuGet 개발 속도가 느려지고 .NET 개발자가 의존하는 코드 라이브러리가 버려지거나 더 이상 사용되지 않게 될 수 있습니다. 지금 당장 행동해야 합니다!

우리의 솔루션

기존 그래픽 라이브러리와 새로운 그래픽 라이브러리 간의 변환을 위한 중간 그래픽 형식입니다.

클래스 라이브러리 개발자로서, 귀하의 공개 Bitmap, Color, Rectangle, Font, 그리고 Size 입력 및 출력은 모든 새로운 표준을 지원하는 단 하나의 유형만이 될 수 있습니다. 내부적으로는 당신이 좋아하는 일을 계속할 수 있습니다.

IronDrawing은 .NET Framework 4.62와 하위 호환되며, 모든 버전의 .NET ( .NET 8 포함)을 지원합니다.

IronDrawing의 개발 및 릴리스는 Bitmap, Color, Rectangle, Font, 그리고 Size와 같은 중요한 클래스들에 대한 통일된 형식의 부족 문제를 해결하는 오픈 소스 솔루션을 제공합니다. IronSoftware.DrawingSystem.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.Bitmap
    • System.Drawing.Image
    • SkiaSharp.SKBitmap
    • SkiaSharp.SKImage
    • SixLabors.ImageSharp
    • Microsoft.Maui.Graphics.Platform.PlatformImage
  • 색상 : 범용적으로 호환되는 색상 클래스입니다. IronSoftware.Drawing.Color와 다음 지원된 것들 간의 암시적 캐스팅:
    • System.Drawing.Color
    • SkiaSharp.SKColor
    • SixLabors.ImageSharp.Color
    • SixLabors.ImageSharp.PixelFormats
  • Rectangle: 보편적으로 호환 가능한 Rectangle 클래스. IronSoftware.Drawing.Rectangle와 다음 지원된 것들 간의 암시적 캐스팅:
    • System.Drawing.Rectangle
    • SkiaSharp.SKRect
    • SkiaSharp.SKRectI
    • SixLabors.ImageSharp.Rectangle
  • Font : 범용적으로 호환되는 Font 클래스입니다. IronSoftware.Drawing.Font와 다음 지원된 것들 간의 암시적 캐스팅:
    • System.Drawing.Font
    • SkiaSharp.SKFont
    • SixLabors.Fonts.Font

호환성

IronSoftware.Drawing는 다음과의 크로스 플랫폼 지원 호환성을 제공합니다:

  • .NET 8, .NET 7, .NET 6, .NET 5, .NET Core, .NET Standard 및 .NET Framework 4.62 이상
  • 윈도우, macOS, 리눅스, Docker, Azure, AWS

설치

IronDrawing (IronSoftware.Drawing) NuGet 패키지는 설치가 빠르고 쉽습니다. 다음과 같이 패키지를 설치해 주세요:

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");
$vbLabelText   $csharpLabel

색상 예시

: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}");
$vbLabelText   $csharpLabel

직사각형 예시

: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);
$vbLabelText   $csharpLabel

글꼴 예시

: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}");
}
$vbLabelText   $csharpLabel

지원 가능

특허

라이선스 정보는 LICENSE.txt 파일에서 확인할 수 있습니다.

기여하다

IronDrawing 오픈소스 프로젝트에 기여하고 싶으시다면, GitHub 저장소에 풀 리퀘스트를 보내기 전에 라이선스를 읽어보시기 바랍니다.

정보

Iron Software 에 대한 자세한 정보는 당사 웹사이트를 방문하십시오.https://ironsoftware.com/

Iron Software 의 지원

일반적인 지원 및 기술 관련 문의는 다음 이메일 주소로 보내주시기 바랍니다:mailto:support@ironsoftware.com

커티스 차우
기술 문서 작성자

커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다.

커티스는 개발 분야 외에도 사물 인터넷(IoT)에 깊은 관심을 가지고 있으며, 하드웨어와 소프트웨어를 통합하는 혁신적인 방법을 연구합니다. 여가 시간에는 게임을 즐기거나 디스코드 봇을 만들면서 기술에 대한 애정과 창의성을 결합합니다.

시작할 준비 되셨나요?
Nuget 다운로드 15,596,264 | 버전: 2025.3 방금 출시되었습니다
Still Scrolling Icon

아직도 스크롤하고 계신가요?

빠른 증거를 원하시나요? PM > Install-Package IronSoftware.System.Drawing
샘플을 실행하세요 HTML이 PDF로 변환되는 것을 지켜보세요.