System.Drawing.Common'ı .NET'te Değiştirmek için C# Bitmap Kütüphanesi

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

IronDrawing ücretsiz, açık kaynaklıdır ve çoğu .NET çizim kütüphanesi formatını destekler

IronDrawing, Iron Software tarafından orijinal olarak geliştirilmiş ve C# Yazılım Mühendislerinin Windows, macOS ve Linux platformlarında .NET projelerinde System.Drawing.Common yerine kullandıkları açık kaynaklı bir kütüphanedir.

.NET 5, 6, 7 ve 8 için grafikler, resimler ve yazı tiplerini destekleyen sınıf kütüphaneleri ve NuGet paketleri geliştirmek kolay olmalıdır.

IronDrawing, gelişmekte olan tüm yeni önerilen .NET 5, 6, 7 ve 8 grafik standartları arasında sorunsuz bir köprü görevi görür - böylece sadece tercih ettiğiniz biri için geliştirmeniz gerekir.

IronDrawing ücretsiz, açık kaynaklıdır ve çoğu .NET çizim kütüphanesi formatını destekler

Bağlam

Microsoft .NET, dünya çapında milyonlarca yazılım geliştiricisi tarafından kullanılan çok platformlu, oldukça uyumlu bir yazılım çatısıdır. Microsoft, System.Drawing.Common'nin sadece Windows platformlarında destekleneceğini duyurdu ve bu bir büyük değişiklik olarak nitelendiriliyor.

Bu, System.Drawing.Common kullanan cati platform kutuphanelerini sürdüren .NET kütüphane geliştiricileri icin sorunlu, çünkü Microsoft'un önerilen eylemi kütüphanenizi yeniden yapılandırarak Windows disi kullanicilara destek vermenizi gerektiriyor. Gönüllülerin ve akademisyenlerin her bir NuGet paketi ve sınıf kütüphanesini yeni önerilen grafik kütüphanelerinin her birini kullanmak için yeniden inşa etmeleri beklenir ve bu da modern .NET'in benimsenmesini yavaşlatacak bir teknik borç yaratacaktır.

Sonuçta .NET kullanırken NuGet kullanırız.

NuGet paket geliştiricileri, kendi başımıza yazmaya binlerce saat sürecek kodu günlük olarak önceden paketlenmiş .NET'i ileriye taşımak konusunda bize büyük bir iyilik yapıyorlar.

Bu geri uyumlu değişiklik NuGet geliştirmenizi yavaşlatacak ve .NET geliştiricilerinin bağımlı olduğu kod kütüphanelerinin terkedilmesine veya eskimiş olmasına yol açabilir. Hemen harekete geçmeliyiz!

Çözümümüz

Eski ve yeni grafik kütüphaneleri arasında dönüşüm yapan bir ara grafik formatı.

Bir sınıf kutuphanesi geliştiricisi olarak, herkese açık Bitmap, Color, Rectangle, Font ve Size Girdi ve Ciktilariniz sadece tüm yeni standartlari destekleyen tek bir tip olabilir. Dahili olarak istediğiniz gibi devam edebilirsiniz.

IronDrawing, .NET Framework 4.62 ile geriye dönük uyumludur, tüm .NET sürümlerini ( .NET 8 dahil) destekler.

IronDrawing'in geliştirilmesi ve piyasaya sürülmesi, önemli sınıflar bagi Bitmap, Color, Rectangle, Font ve Size icin bir duzgun format eksikliğine bir açık kaynak cozum getirerek bu sorunu cözüyor. IronSoftware.Drawing, System.Drawing, Microsoft.Maui, SkiaSharp ve SixLabors'deki bu türler arasındaki uygulamalari sorunsuz bir şekilde dönüştürur. Bu, geliştirici olarak kütüphanenizdeki bu sınıf örneklerinin tümünü değiştirmenize gerek olmadığını sağlar.

Örneğin, System.Drawing.Bitmap kullanıyorsanız, IronDrawing'in AnyBitmap sınıfını kullanabilirsiniz. Bu sınıf su türlerin her birine dolaylı dönüşümler içermektedir: System.Drawing.Bitmap, System.Drawing.Image, SkiaSharp.SKBitmap, SkiaSharp.SKImage, SixLabors.ImageSharp, Microsoft.Maui.Graphics.Platform.PlatformImage.

Neden Bunu Ücretsiz Yapıyoruz?

IronDrawing'u geliştirdik çünkü Iron Software'deki biz uzun vadeli, kıdemli .NET geliştiricileriyiz ve .NET'in gelişiminden yanayız. .NET 7 ile görüldüğü gibi, .NET'in büyümesini ve gelişimini görmek bizi mutlu ediyor. NuGet'i her gün kullanıyoruz ve eminim siz de kullanıyorsunuzdur. Biz destekliyoruz ve System.Drawing'den gelecege doğru ve kolay bir geçişe teşvik etmeyi umuyoruz.

Tüm .NET sınıf kütüphanesi ve NuGet geliştirmenin daha kolay olmasını istiyoruz, böylece NuGet Ekosistemi gelişmeye devam ettikçe tüm .NET geliştiricileri fayda sağlar.

IronSoftware.Drawing Özellikleri

  • AnyBitmap: Evrensel olarak uyumlu Bitmap sınıfı. IronSoftware.Drawing.AnyBitmap ve aşağıdakiler arasında dolaylı dönüştürme desteği:
    • System.Drawing.Bitmap
    • System.Drawing.Image
    • SkiaSharp.SKBitmap
    • SkiaSharp.SKImage
    • SixLabors.ImageSharp
    • Microsoft.Maui.Graphics.Platform.PlatformImage
  • Renk: Evrensel uyumlu bir Renk sınıfı. IronSoftware.Drawing.Color ve aşağıdakiler arasında dolaylı dönüştürme desteği:
    • System.Drawing.Color
    • SkiaSharp.SKColor
    • SixLabors.ImageSharp.Color
    • SixLabors.ImageSharp.PixelFormats
  • Rectangle: Evrensel olarak uyumlu Dikdörtgen sınıfı. IronSoftware.Drawing.Rectangle ve aşağıdakiler arasında dolaylı dönüştürme desteği:
    • System.Drawing.Rectangle
    • SkiaSharp.SKRect
    • SkiaSharp.SKRectI
    • SixLabors.ImageSharp.Rectangle
  • Yazı Tipi: Evrensel uyumlu bir Yazı Tipi sınıfı. IronSoftware.Drawing.Font ve aşağıdakiler arasında dolaylı dönüştürme desteği:
    • System.Drawing.Font
    • SkiaSharp.SKFont
    • SixLabors.Fonts.Font

Uyumluluk

IronSoftware.Drawing, su ortamlarla platformlar arasi uyumluluk sağlar:

  • .NET 8, .NET 7, .NET 6, .NET 5, .NET Core, .NET Standard ve .NET Framework 4.62+
  • Windows, macOS, Linux, Docker, Azure ve AWS

Kurulum

IronDrawing (IronSoftware.Drawing) NuGet paketini yüklemek hızlı ve kolaydır. Lütfen paketi şu şekilde yükleyin:

Install-Package IronSoftware.System.Drawing

Alternatif olarak, resmi NuGet web sitesinden doğrudan indirilebilir.

Yüklendikten sonra, C# kodunuzun basina using IronSoftware.Drawing; ekleyerek başlayabilirsiniz.

Kod Örnekleri

AnyBitmap Örneği

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

Renk Örneği

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

Dikdörtgen Örneği

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

Yazı Tipi Örneği

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

Destek Mevcut

Lisans

Lisans bilgileri burada bulunabilir: LICENSE.txt

Katkıda Bulun

IronDrawing açık kaynak projesine katkıda bulunmak isterseniz, bir pull-request yapmadan önce lisansı okumanız gerekir GitHub deposunda.

Bilgi

Iron Software hakkında daha fazla bilgi için lütfen web sitemizi ziyaret edin: https://ironsoftware.com/

Iron Software'dan Destek

Genel destek ve teknik sorular için lütfen bize e-posta gönderin: mailto:support@ironsoftware.com

Curtis Chau
Teknik Yazar

Curtis Chau, Bilgisayar Bilimleri alanında lisans derecesine sahiptir (Carleton Üniversitesi) ve Node.js, TypeScript, JavaScript ve React konularında uzmanlaşmış ön uç geliştirme üzerine uzmanlaşmıştır. Kullanıcı dostu ve estetik açıdan hoş arayüzler tasarlamaya tutkuyla bağlı olan Curtis, modern çerç...

Daha Fazlasını Oku
Başlamaya Hazır mısınız?
Nuget İndirmeler 16,168,200 | Sürüm: 2025.3 just released
Still Scrolling Icon

Hala Kaydiriyor musunuz?

Hızlı bir kanit mi istiyorsunuz? PM > Install-Package IronSoftware.System.Drawing
bir örnek çalıştır HTML'nizin PDF olduğunu izleyin.