# C# Bitmap Library to Replace `System.Drawing.Common` in .NET
## IronDrawing jest darmowy, open-source i obsługuje większość formatów bibliotek rysunkowych .NET
**IronDrawing** to biblioteka open source pierwotnie opracowana przez Iron Software, która pomaga inżynierom oprogramowania C# zastąpić `System.Drawing.Common` w projektach .NET na platformach Windows, macOS i Linux.
Tworzenie bibliotek klas i pakietów NuGet dla platform .NET 5, 6, 7 i 8, obsługujących grafikę, obrazy i czcionki, _powinno_ być łatwe.
IronDrawing pełni rolę płynnego pomostu między wszystkimi nowymi, proponowanymi standardami graficznymi .NET 5, 6, 7 i 8 w miarę ich ewolucji — dzięki czemu wystarczy tworzyć oprogramowanie dla tego**, który preferujesz**.
<div class="content-img-align-center">
<div class="center-image-wrapper">
<img src="/static-assets/drawing/irondrawing-get-started.webp" alt="IronDrawing jest bezpłatny, oparty na otwartym kodzie źródłowym i obsługuje większość formatów bibliotek rysunkowych .NET" class="img-responsive add-shadow" width="645" height="618" />
</div>
</div>
<div class="hsg-featured-snippet">
<h2>Kroki techniczne pozwalające uniknąć wyjątku "system.drawing.common nie jest obsługiwany na tej platformie"</h2>
<ol>
<li>Implement <strong>System.drawing.common</strong> is not possible for .NET 6 and .NET 7 & 8 on Linux and macOS platforms</li>
<li>Użycie System.Drawing.Common na tych platformach spowoduje wyświetlenie komunikatu o wyjątku</li>
<li>Ustaw konfigurację środowiska uruchomieniowego <strong>System.Drawing.EnableUnixSupport</strong> na <strong>wartość true</strong> dla .NET 6</li>
<li>Obsługa System.Drawing.Common nie jest już dostępna w .NET 7 i 8</li>
<li>Użyj biblioteki open source <strong>IronSoftware.Drawing,</strong> aby zastąpić <strong>System.Drawing.Common</strong> w .NET 7</li>
</ol>
</div>
### Kontekst
Microsoft .NET Framework to wieloplatformowy, wysoce kompatybilny framework programistyczny używany przez miliony programistów na całym świecie. Firma Microsoft [ogłosiła](https://learn.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/6.0/system-drawing-common-windows-only) **istotną zmianę,** w wyniku której `System.Drawing.Common` będzie obsługiwane wyłącznie na platformach Windows.
Stanowi to problem dla twórców bibliotek .NET, którzy utrzymują biblioteki wieloplatformowe wykorzystujące `System.Drawing.Common`, ponieważ [zalecane](https://learn.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/6.0/system-drawing-common-windows-only#recommended-action) przez Microsoft [działanie](https://learn.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/6.0/system-drawing-common-windows-only#recommended-action) wymaga przebudowy biblioteki w celu obsługi użytkowników spoza środowiska Windows. Od wolontariuszy i naukowców oczekuje się przebudowy każdego pakietu NuGet i biblioteki klas w celu wykorzystania **każdej** z nowych sugerowanych bibliotek graficznych w miarę ich pojawiania się, co powoduje powstanie długu technicznego, który spowolni wdrażanie nowoczesnego .NET.
Ostatecznie, kiedy korzystamy z .NET, korzystamy z NuGet.
_Twórcy pakietów NuGet wyświadczają nam wszystkim przysługę, rozwijając platformę .NET i dostarczając gotowe kody, których samodzielne napisanie zajęłoby nam codziennie tysiące godzin._
Ta **przełomowa zmiana** spowolni rozwój NuGet i może doprowadzić do porzucenia lub dezaktualizacji bibliotek kodu, na których polegają programiści .NET. Musimy działać już teraz!
### Nasze rozwiązanie
Pośredni format graficzny, który konwertuje dane między wszystkimi starymi i nowymi bibliotekami graficznymi.
Jako twórca bibliotek klas, Twoje publiczne `Bitmap`, `Color`, `Rectangle`, `Font` oraz `Size` dane wejściowe i wyjściowe mogą być tylko jednego typu, który obsługuje wszystkie nowe standardy. Wewnętrznie możesz nadal robić to, co lubisz.
**IronDrawing jest kompatybilny wstecznie z .NET Framework 4.62 i obsługuje wszystkie wersje .NET (w tym .NET 8).**
Opracowanie i wydanie IronDrawing rozwiązuje ten problem, zapewniając rozwiązanie open source w odpowiedzi na brak jednolitego formatu dla ważnych klas, takich jak `Bitmap`, `Color`, `Rectangle`, `Font` oraz `Size`. `IronSoftware.Drawing` płynnie konwertuje między implementacjami tych typów w `System.Drawing`, `Microsoft.Maui`, `SkiaSharp` i `SixLabors`. Dzięki temu programista nie musi zastępować wszystkich wystąpień tych klas w swojej bibliotece.
Na [przykład](#anchor-anybitmap-example), jeśli używasz `System.Drawing.Bitmap`, możesz skorzystać z klasy `AnyBitmap` biblioteki IronDrawing, która obsługuje niejawne konwersje do dowolnego z tych typów: `System.Drawing.Bitmap`, `System.Drawing.Image`, `SkiaSharp.SKBitmap`, `SkiaSharp.SKImage`, `SixLabors.ImageSharp`, `Microsoft.Maui.Graphics.Platform.PlatformImage`.
### Dlaczego robimy to za darmo
Opracowaliśmy IronDrawing, ponieważ w Iron Software jesteśmy doświadczonymi programistami .NET, którym zależy na rozwoju platformy .NET i pragniemy, aby się ona rozwijała i odniosła sukces. Cieszymy się, że platforma .NET rozwija się i ewoluuje, czego przykładem jest .NET 7. Korzystamy z NuGet przez cały dzień i jestem pewien, że Państwo również. Wspieramy i mamy nadzieję zachęcić do łatwego przejścia w przyszłość i odejścia od `System.Drawing`.
Chcemy, aby tworzenie bibliotek klas .NET i NuGet było łatwiejsze, tak aby ekosystem NuGet nadal się rozwijał, a wszyscy programiści .NET odnosili z tego korzyści.
## `IronSoftware.Drawing` Funkcje
- **`AnyBitmap`**: Uniwersalnie kompatybilna klasa Bitmap. Obsługiwane jest niejawne rzutowanie między `IronSoftware.Drawing.AnyBitmap` a następującymi typami:
- `System.Drawing.Bitmap`
- `System.Drawing.Image`
- `SkiaSharp.SKBitmap`
- `SkiaSharp.SKImage`
- `SixLabors.ImageSharp`
- `Microsoft.Maui.Graphics.Platform.PlatformImage`
- **Color**: uniwersalnie kompatybilna klasa Color. Obsługiwane jest niejawne rzutowanie między `IronSoftware.Drawing.Color` a następującymi typami:
- `System.Drawing.Color`
- `SkiaSharp.SKColor`
- `SixLabors.ImageSharp.Color`
- `SixLabors.ImageSharp.PixelFormats`
- **`Rectangle`**: Uniwersalnie kompatybilna klasa Rectangle. Obsługiwane jest niejawne rzutowanie między `IronSoftware.Drawing.Rectangle` a następującymi typami:
- `System.Drawing.Rectangle`
- `SkiaSharp.SKRect`
- `SkiaSharp.SKRectI`
- `SixLabors.ImageSharp.Rectangle`
- **Font**: Uniwersalnie kompatybilna klasa Font. Obsługiwane jest niejawne rzutowanie między `IronSoftware.Drawing.Font` a następującymi typami:
- `System.Drawing.Font`
- `SkiaSharp.SKFont`
- `SixLabors.Fonts.Font`
### Kompatybilność
**`IronSoftware.Drawing`** jest kompatybilny z następującymi platformami:
- .NET 8, .NET 7, .NET 6, .NET 5, .NET Core, .NET Standard oraz .NET Framework 4.62+
- Windows, macOS, Linux, Docker, Azure i AWS
## Instalacja
Instalacja pakietu NuGet IronDrawing (`IronSoftware.Drawing`) jest szybka i łatwa. Zainstaluj pakiet w następujący sposób:
```shell
:InstallCmd Install-Package IronSoftware.System.Drawing
```
Alternatywnie można pobrać je bezpośrednio z [oficjalnej strony NuGet](https://www.nuget.org/packages/IronSoftware.System.Drawing).
Po zainstalowaniu możesz rozpocząć pracę, dodając `using IronSoftware.Drawing;` na początku kodu C#.
## Przykłady kodu
### Przykład AnyBitmap
```csharp
:path=/static-assets/drawing/content-code-examples/get-started/anybitmap.cs
```
### Przykład koloru
```csharp
:path=/static-assets/drawing/content-code-examples/get-started/color.cs
```
### Przykład prostokąta
```csharp
:path=/static-assets/drawing/content-code-examples/get-started/rectangle.cs
```
### Przykład czcionki
```csharp
:path=/static-assets/drawing/content-code-examples/get-started/font.cs
```
## Dostępna pomoc techniczna
### Licencja
Informacje dotyczące licencji można znaleźć tutaj: [LICENSE.txt](https://github.com/iron-software/IronSoftware.System.Drawing/blob/master/LICENSE.txt)
### Współtwórz
Jeśli chcesz wnieść swój wkład w projekt open source IronDrawing, przeczytaj [licencję](https://github.com/iron-software/IronSoftware.System.Drawing/blob/master/LICENSE.txt) przed wysłaniem pull requestu do [repozytorium na GitHubie](https://github.com/iron-software/IronSoftware.System.Drawing).
### Informacje
Więcej informacji na temat Iron Software można znaleźć na naszej stronie internetowej: [https://ironsoftware.com/](https://ironsoftware.com/)
### Wsparcie od Iron Software
W sprawie ogólnego wsparcia i pytań technicznych prosimy o kontakt mailowy pod adresem: [support@ironsoftware.com](mailto:support@ironsoftware.com)
IronDrawing jest darmowy, open-source i obsługuje większość formatów bibliotek rysunkowych .NET
IronDrawing to biblioteka open source pierwotnie opracowana przez Iron Software, która pomaga inżynierom oprogramowania C# zastąpić System.Drawing.Common w projektach .NET na platformach Windows, macOS i Linux.
Tworzenie bibliotek klas i pakietów NuGet dla platform .NET 5, 6, 7 i 8, obsługujących grafikę, obrazy i czcionki, powinno być łatwe.
IronDrawing pełni rolę płynnego pomostu między wszystkimi nowymi, proponowanymi standardami graficznymi .NET 5, 6, 7 i 8 w miarę ich ewolucji — dzięki czemu wystarczy tworzyć oprogramowanie dla tego**, który preferujesz**.
Kroki techniczne pozwalające uniknąć wyjątku "system.drawing.common nie jest obsługiwany na tej platformie"
Implement System.drawing.common is not possible for .NET 6 and .NET 7 & 8 on Linux and macOS platforms
Użycie System.Drawing.Common na tych platformach spowoduje wyświetlenie komunikatu o wyjątku
Ustaw konfigurację środowiska uruchomieniowego System.Drawing.EnableUnixSupport na wartość true dla .NET 6
Obsługa System.Drawing.Common nie jest już dostępna w .NET 7 i 8
Użyj biblioteki open source IronSoftware.Drawing, aby zastąpić System.Drawing.Common w .NET 7
Kontekst
Microsoft .NET Framework to wieloplatformowy, wysoce kompatybilny framework programistyczny używany przez miliony programistów na całym świecie. Firma Microsoft ogłosiłaistotną zmianę, w wyniku której System.Drawing.Common będzie obsługiwane wyłącznie na platformach Windows.
Stanowi to problem dla twórców bibliotek .NET, którzy utrzymują biblioteki wieloplatformowe wykorzystujące System.Drawing.Common, ponieważ zalecane przez Microsoft działanie wymaga przebudowy biblioteki w celu obsługi użytkowników spoza środowiska Windows. Od wolontariuszy i naukowców oczekuje się przebudowy każdego pakietu NuGet i biblioteki klas w celu wykorzystania każdej z nowych sugerowanych bibliotek graficznych w miarę ich pojawiania się, co powoduje powstanie długu technicznego, który spowolni wdrażanie nowoczesnego .NET.
Ostatecznie, kiedy korzystamy z .NET, korzystamy z NuGet.
Twórcy pakietów NuGet wyświadczają nam wszystkim przysługę, rozwijając platformę .NET i dostarczając gotowe kody, których samodzielne napisanie zajęłoby nam codziennie tysiące godzin.
Ta przełomowa zmiana spowolni rozwój NuGet i może doprowadzić do porzucenia lub dezaktualizacji bibliotek kodu, na których polegają programiści .NET. Musimy działać już teraz!
Nasze rozwiązanie
Pośredni format graficzny, który konwertuje dane między wszystkimi starymi i nowymi bibliotekami graficznymi.
Jako twórca bibliotek klas, Twoje publiczne Bitmap, Color, Rectangle, Font oraz Size dane wejściowe i wyjściowe mogą być tylko jednego typu, który obsługuje wszystkie nowe standardy. Wewnętrznie możesz nadal robić to, co lubisz.
IronDrawing jest kompatybilny wstecznie z .NET Framework 4.62 i obsługuje wszystkie wersje .NET (w tym .NET 8).
Opracowanie i wydanie IronDrawing rozwiązuje ten problem, zapewniając rozwiązanie open source w odpowiedzi na brak jednolitego formatu dla ważnych klas, takich jak Bitmap, Color, Rectangle, Font oraz Size. IronSoftware.Drawing płynnie konwertuje między implementacjami tych typów w System.Drawing, Microsoft.Maui, SkiaSharp i SixLabors. Dzięki temu programista nie musi zastępować wszystkich wystąpień tych klas w swojej bibliotece.
Na przykład, jeśli używasz System.Drawing.Bitmap, możesz skorzystać z klasy AnyBitmap biblioteki IronDrawing, która obsługuje niejawne konwersje do dowolnego z tych typów: System.Drawing.Bitmap, System.Drawing.Image, SkiaSharp.SKBitmap, SkiaSharp.SKImage, SixLabors.ImageSharp, Microsoft.Maui.Graphics.Platform.PlatformImage.
Dlaczego robimy to za darmo
Opracowaliśmy IronDrawing, ponieważ w Iron Software jesteśmy doświadczonymi programistami .NET, którym zależy na rozwoju platformy .NET i pragniemy, aby się ona rozwijała i odniosła sukces. Cieszymy się, że platforma .NET rozwija się i ewoluuje, czego przykładem jest .NET 7. Korzystamy z NuGet przez cały dzień i jestem pewien, że Państwo również. Wspieramy i mamy nadzieję zachęcić do łatwego przejścia w przyszłość i odejścia od System.Drawing.
Chcemy, aby tworzenie bibliotek klas .NET i NuGet było łatwiejsze, tak aby ekosystem NuGet nadal się rozwijał, a wszyscy programiści .NET odnosili z tego korzyści.
IronSoftware.Drawing Funkcje
AnyBitmap: Uniwersalnie kompatybilna klasa Bitmap. Obsługiwane jest niejawne rzutowanie między IronSoftware.Drawing.AnyBitmap a następującymi typami:
System.Drawing.Bitmap
System.Drawing.Image
SkiaSharp.SKBitmap
SkiaSharp.SKImage
SixLabors.ImageSharp
Microsoft.Maui.Graphics.Platform.PlatformImage
Color: uniwersalnie kompatybilna klasa Color. Obsługiwane jest niejawne rzutowanie między IronSoftware.Drawing.Color a następującymi typami:
System.Drawing.Color
SkiaSharp.SKColor
SixLabors.ImageSharp.Color
SixLabors.ImageSharp.PixelFormats
Rectangle: Uniwersalnie kompatybilna klasa Rectangle. Obsługiwane jest niejawne rzutowanie między IronSoftware.Drawing.Rectangle a następującymi typami:
System.Drawing.Rectangle
SkiaSharp.SKRect
SkiaSharp.SKRectI
SixLabors.ImageSharp.Rectangle
Font: Uniwersalnie kompatybilna klasa Font. Obsługiwane jest niejawne rzutowanie między IronSoftware.Drawing.Font a następującymi typami:
System.Drawing.Font
SkiaSharp.SKFont
SixLabors.Fonts.Font
Kompatybilność
IronSoftware.Drawing jest kompatybilny z następującymi platformami:
.NET 8, .NET 7, .NET 6, .NET 5, .NET Core, .NET Standard oraz .NET Framework 4.62+
Windows, macOS, Linux, Docker, Azure i AWS
Instalacja
Instalacja pakietu NuGet IronDrawing (IronSoftware.Drawing) jest szybka i łatwa. Zainstaluj pakiet w następujący sposób:
Po zainstalowaniu możesz rozpocząć pracę, dodając using IronSoftware.Drawing; na początku kodu C#.
Przykłady kodu
Przykład AnyBitmap
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 processvar bitmap = AnyBitmap.FromFile("FILE_PATH");// Save the AnyBitmap object as a JPEG filebitmap.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 databasevar bytes = bitmap.ExportBytes();// Create a memory stream to export the AnyBitmap as a JPEG stream with 100% qualityusing (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 fileSystem.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 processingIronSoftware.Drawing.AnyBitmap anyBitmap = AnyBitmap.FromBitmap(image);// Save the resulting AnyBitmap from casting as a PNG fileanyBitmap.SaveAs("result-from-casting.png");
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");
ImportsIronSoftware.DrawingImportsSystem.IOImportsSystem.Drawing' Create a new AnyBitmap object from a file' Replace "FILE_PATH" with the actual path of the image you want to processPrivate bitmap = AnyBitmap.FromFile("FILE_PATH")' Save the AnyBitmap object as a JPEG filebitmap.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 databaseDim bytes = bitmap.ExportBytes()' Create a memory stream to export the AnyBitmap as a JPEG stream with 100% qualityUsing 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 resourcesEndUsing' Casting between System.Drawing.Bitmap and IronSoftware.Drawing.AnyBitmap' Load a System.Drawing.Bitmap from the same fileDim 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 processingDim anyBitmap AsIronSoftware.Drawing.AnyBitmap = AnyBitmap.FromBitmap(image)' Save the resulting AnyBitmap from casting as a PNG fileanyBitmap.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")
Przykład koloru
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}");
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}");
ImportsIronSoftware.DrawingImportsSystem' 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 AsColor = Color.FromHex("#191919")' Create a new Color object from RGB values.Private fromRgb AsColor = Color.FromRgb(255, 255, 0)' Create a new Color object using an enumeration.Private fromEnum AsColor = Color.Crimson' Casting between System.Drawing.Color and IronSoftware.Drawing.Color.Private drawingColor AsSystem.Drawing.Color = System.Drawing.Color.Red' Convert System.Drawing.Color to IronSoftware.Drawing.Color.Private ironColor AsIronSoftware.Drawing.Color = Color.FromSystemColor(drawingColor)' Access the alpha, red, green, and blue components of the IronSoftware.Drawing.Color.Private alpha AsByte = ironColor.APrivate red AsByte = ironColor.RPrivate green AsByte = ironColor.GPrivate blue AsByte = 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 AsDouble = 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}")
Przykład prostokąta
using IronSoftware.Drawing;using System.Drawing;// Declare an IronSoftware.Drawing.Rectangle objectIronSoftware.Drawing.Rectangle ironRectangle = new IronSoftware.Drawing.Rectangle(5, 5, 50, 50);// Declare a System.Drawing.Rectangle objectSystem.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 environmentConsole.WriteLine(ironRectangle.X);Console.WriteLine(ironRectangle.Y);Console.WriteLine(ironRectangle.Width);Console.WriteLine(ironRectangle.Height);
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);
ImportsIronSoftware.DrawingImportsSystem.Drawing' Declare an IronSoftware.Drawing.Rectangle objectPrivate ironRectangle As New IronSoftware.Drawing.Rectangle(5, 5, 50, 50)' Declare a System.Drawing.Rectangle objectPrivate 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 environmentConsole.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)
Przykład czcionki
using System;using System.Drawing;using IronSoftware.Drawing;// Create a new Font object with a specified font family, style, and sizeIronSoftware.Drawing.Font font = new IronSoftware.Drawing.Font("Times New Roman", FontStyle.Italic | FontStyle.Bold, 30);// Create a new instance of System.Drawing.FontSystem.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 correctnessConsole.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}");}
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}");
}
ImportsSystemImportsSystem.DrawingImportsIronSoftware.Drawing' Create a new Font object with a specified font family, style, and sizePrivate font As New IronSoftware.Drawing.Font("Times New Roman", FontStyle.ItalicOrFontStyle.Bold, 30)' Create a new instance of System.Drawing.FontPrivate 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 AsString = ironFont.FamilyName' Get the font family name Dim style AsFontStyle = ironFont.Style' Get the combined font style (italic, bold, etc.) Dim size AsSingle = ironFont.Size' Get the font size Dim isItalic AsBoolean = ironFont.Italic' Determine if the font style includes Italic Dim isBold AsBoolean = ironFont.Bold' Determine if the font style includes Bold ' Output the font properties to verify correctnessConsole.WriteLine($"Family: {familyName}, Style: {style}, Size: {size}, Italic: {isItalic}, Bold: {isBold}")Catch e1 AsInvalidCastExceptionConsole.WriteLine("The conversion between System.Drawing.Font and IronSoftware.Drawing.Font is not directly supported.")Catch ex AsExceptionConsole.WriteLine($"An error occurred: {ex.Message}")EndTry
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
Dostępna pomoc techniczna
Licencja
Informacje dotyczące licencji można znaleźć tutaj: LICENSE.txt
Współtwórz
Jeśli chcesz wnieść swój wkład w projekt open source IronDrawing, przeczytaj licencję przed wysłaniem pull requestu do repozytorium na GitHubie.
Informacje
Więcej informacji na temat Iron Software można znaleźć na naszej stronie internetowej: https://ironsoftware.com/
Wsparcie od Iron Software
W sprawie ogólnego wsparcia i pytań technicznych prosimy o kontakt mailowy pod adresem: support@ironsoftware.com
Curtis Chau posiada tytuł licencjata z informatyki (Uniwersytet Carleton) i specjalizuje się w front-endowym rozwoju, z ekspertką w Node.js, TypeScript, JavaScript i React. Pasjonuje się tworzeniem intuicyjnych i estetycznie przyjemnych interfejsów użytkownika, Curtis cieszy się pracą z nowoczesnymi frameworkami i tworzeniem dobrze zorganizowanych, atrakcyjnych wizualnie podręczników.