FrameworkExtensions.System.Drawing
1.0.0.70
See the version list below for details.
dotnet add package FrameworkExtensions.System.Drawing --version 1.0.0.70
NuGet\Install-Package FrameworkExtensions.System.Drawing -Version 1.0.0.70
<PackageReference Include="FrameworkExtensions.System.Drawing" Version="1.0.0.70" />
<PackageVersion Include="FrameworkExtensions.System.Drawing" Version="1.0.0.70" />
<PackageReference Include="FrameworkExtensions.System.Drawing" />
paket add FrameworkExtensions.System.Drawing --version 1.0.0.70
#r "nuget: FrameworkExtensions.System.Drawing, 1.0.0.70"
#:package FrameworkExtensions.System.Drawing@1.0.0.70
#addin nuget:?package=FrameworkExtensions.System.Drawing&version=1.0.0.70
#tool nuget:?package=FrameworkExtensions.System.Drawing&version=1.0.0.70
Extensions to System.Drawing
Extension methods for System.Drawing types (bitmaps, images, colors, graphics).
Extension Methods
Bitmap Extensions (Bitmap)
Bitmap Locking
Lock(...)- Lock bitmap for direct pixel access (8 overloads for different combinations)Lock()- Lock entire bitmap with ReadWrite modeLock(Rectangle)- Lock regionLock(ImageLockMode)- Lock with specific modeLock(PixelFormat)- Lock with specific formatLock(Rectangle, ImageLockMode)Lock(Rectangle, PixelFormat)Lock(ImageLockMode, PixelFormat)Lock(Rectangle, ImageLockMode, PixelFormat)- Full control- Returns format-specific
IBitmapLockerimplementation
Transformations
ConvertPixelFormat(PixelFormat)- Convert bitmap to different pixel formatCrop(Rectangle, PixelFormat = DontCare)- Extract region from bitmapResize(int width, int height, InterpolationMode = Bicubic)- Resize bitmapRotated(float angle, Point? center = null)- Create rotated copy of bitmapRotateInplace(float angle, Point? center = null)- Rotate bitmap in-placeRotateTo(Bitmap target, float angle, Point? center = null)- Rotate to target bitmap
Image Extensions (Image)
Multi-Page Support
GetPageAt(int page)- Get specific page from multi-page image (e.g., TIFF)GetPageCount()- Get total number of pages in image
Save Operations
SaveToPng(FileInfo/string)- Save image as PNGSaveToTiff(string)- Save image as TIFFSaveToJpeg(string/Stream, double quality = 1)- Save as JPEG with quality (0.0-1.0)
Conversions
ToIcon(int targetRes = 0)- Convert image to IconToBase64DataUri()- Convert to Base64 data URI stringFromBase64DataUri(string)(static-like extension on string) - Create image from Base64 data URI
Image Processing
MakeGrayscale()- Convert image to grayscaleThreshold(byte threshold = 127)- Apply threshold filter (black/white)ApplyPixelProcessor(Func<Color, Color> processor)- Apply custom pixel transformation functionMirrorAlongX()- Mirror horizontallyMirrorAlongY()- Mirror verticallyResize(int longSide)- Resize to fit within square, keep aspectResize(int longSide, Color fillColor)- Resize with fill colorResize(int width, int height, bool keepAspect = true, Color? fillColor = null)- Resize with optionsResize(int width = -1, int height = -1, InterpolationMode = Default)- Resize with interpolationRotate(float angle)- Rotate image by angleGetRectangle(Rectangle)- Extract rectangular regionReplaceColorWithTransparency(Color)- Replace specific color with transparency
Color Extensions (Color)
Color Space Conversion
Rgb/RgbNormalized- Convert to RGB color spaceHsl/HslNormalized- Convert to HSL (Hue, Saturation, Lightness)Hsv/HsvNormalized- Convert to HSV (Hue, Saturation, Value)Hwb/HwbNormalized- Convert to HWB (Hue, Whiteness, Blackness)Cmyk/CmykNormalized- Convert to CMYK (Cyan, Magenta, Yellow, Key)Xyz/XyzNormalized- Convert to CIE XYZ tristimulus valuesLab/LabNormalized- Convert to CIE Lab* perceptual color spaceYuv/YuvNormalized- Convert to YUV (Luma + chrominance)YCbCr/YCbCrNormalized- Convert to YCbCr digital video encodingDin99/Din99Normalized- Convert to DIN99 (DIN 6176) perceptual space
Color Comparison
IsLike(Color other, byte luminanceDelta = 24, byte chromaUDelta = 7, byte chromaVDelta = 6)- Compare colors in YUV space with toleranceIsLikeNaive(Color other, int tolerance = 2)- Simple RGB comparison with tolerance
Color Blending
BlendWith(Color other, float current, float max)- Interpolate between two colors
Graphics Extensions (Graphics)
DrawString(float x, float y, string text, Font font, Brush brush, ContentAlignment anchor)- Draw text with anchor positioningDrawCross(float/int x, float/int y, float/int size, Pen pen)- Draw cross marker (4 overloads including Point/PointF)DrawCircle(Pen pen, float centerX, float centerY, float radius)- Draw circle outlineFillCircle(Brush brush, float centerX, float centerY, float radius)- Draw filled circle
Rectangle Extensions (Rectangle)
MultiplyBy(int factor)- Scale rectangle uniformlyMultiplyBy(int xfactor, int yfactor)- Scale rectangle with different X/Y factorsCollidesWith(Rectangle/RectangleF)- Check rectangle collisionCollidesWith(Point/PointF)- Check if point is insideCollidesWith(int x, int y)/CollidesWith(float x, float y)- Check if coordinates are insideCenter()- Get center pointSetLeft/SetRight/SetTop/SetBottom(int)- Create new rectangle with modified edge
RectangleF Extensions (RectangleF)
(Similar methods to Rectangle, for floating-point rectangles)
Size Extensions (Size)
Center()- Get center point
Point Extensions (Point)
(Generated from T4 template - numeric operations on points)
FileInfo Extensions (FileInfo)
GetIcon(bool smallIcon = false, bool linkOverlay = false)- Get Windows shell icon for file- Uses native SHGetFileInfo API
Custom Types
IBitmapLocker Interface
Format-specific bitmap pixel access implementations:
- ARGB32BitmapLocker - 32-bit ARGB (Format32bppArgb)
- RGB32BitmapLocker - 32-bit RGB (Format32bppRgb)
- RGB24BitmapLocker - 24-bit RGB (Format24bppRgb)
- RGB565BitmapLocker - 16-bit RGB 565 (Format16bppRgb565)
- ARGB1555BitmapLocker - 16-bit ARGB 1555 (Format16bppArgb1555)
- Gray16BitmapLocker - 16-bit grayscale (Format16bppGrayScale)
- RGB555BitmapLocker - 16-bit RGB 555 (Format16bppRgb555)
- Indexed8BitmapLocker - 8-bit indexed (Format8bppIndexed)
- IndexedBitmapLocker - 1-bit and 4-bit indexed (Format1bppIndexed, Format4bppIndexed)
- UnsupportedDrawingBitmapLocker - Fallback for unsupported formats
Each locker provides optimized pixel access for its specific format.
Color Spaces (System.Drawing.ColorSpaces)
A comprehensive color space conversion and comparison library with zero-cost generic abstractions.
Color Space Types
| Type | Components | Description |
|---|---|---|
Rgb / RgbNormalized |
R, G, B | Standard RGB color model |
Hsl / HslNormalized |
H, S, L | Hue, Saturation, Lightness |
Hsv / HsvNormalized |
H, S, V | Hue, Saturation, Value |
Hwb / HwbNormalized |
H, W, B | Hue, Whiteness, Blackness |
Lab / LabNormalized |
L, a, b | CIE Lab* perceptual color space |
Xyz / XyzNormalized |
X, Y, Z | CIE XYZ tristimulus values |
Yuv / YuvNormalized |
Y, U, V | Luma + chrominance (PAL/NTSC) |
YCbCr / YCbCrNormalized |
Y, Cb, Cr | Digital video color encoding |
Din99 / Din99Normalized |
L, a, b | DIN 6176 perceptual space |
Cmyk / CmykNormalized |
C, M, Y, K | Subtractive printing model |
Distance Calculators (System.Drawing.ColorSpaces.Distances)
| Calculator | Color Space | Description |
|---|---|---|
EuclideanDistance<T> |
Any 3-component | √(Δc1² + Δc2² + Δc3²) |
EuclideanDistance4<T> |
Any 4-component | For CMYK and similar |
ManhattanDistance<T> |
Any 3-component | |Δc1| + |Δc2| + |Δc3| |
ChebyshevDistance<T> |
Any 3-component | max(|Δc1|, |Δc2|, |Δc3|) |
WeightedEuclideanRgbDistance |
RGB | Perception-weighted RGB |
RedmeanDistance |
RGB | Compuserve algorithm |
CIE76Distance |
Lab | ΔE*ab (basic Lab distance) |
CIE94Distance |
Lab | Improved perceptual formula |
CIEDE2000Distance |
Lab | Most accurate perceptual ΔE |
CMCDistance |
Lab | Textile industry (l=1, c=1) |
CMCAcceptabilityDistance |
Lab | Textile acceptability (l=2, c=1) |
DIN99Distance |
DIN99 | German standard DIN 6176 |
All calculators also have *Squared variants for faster comparisons.
Palette Search
using System.Drawing.ColorSpaces;
using System.Drawing.ColorSpaces.Distances;
// Find closest color in palette using perceptual distance
var palette = new[] { Color.Red, Color.Green, Color.Blue };
var index = PaletteSearch.GetMostSimilarColorIndex<CIEDE2000Distance>(palette, targetColor);
// Use any color space for comparison
var index = PaletteSearch.GetMostSimilarColorIndex<EuclideanDistance<Yuv>>(palette, targetColor);
// Cache lookups for repeated queries (e.g., image processing)
var cached = new CachedPalette<EuclideanDistance<Yuv>>(palette);
foreach (var pixel in imagePixels) {
var paletteIndex = cached.GetIndex(pixel); // O(1) after first lookup
}
Color Interpolation (System.Drawing.ColorSpaces.Interpolation)
| Type | Description |
|---|---|
ColorLerp<T> |
Linear interpolation in any 3-component color space |
ColorLerp4<T> |
Linear interpolation in 4-component spaces (CMYK) |
CircularHueLerp<T> |
Hue-aware interpolation for HSL/HSV/HWB |
ColorGradient<T> |
Multi-stop gradient with configurable interpolation |
using System.Drawing.ColorSpaces.Interpolation;
// Interpolate in perceptual Lab space
var lerp = new ColorLerp<Lab>();
var midpoint = lerp.Lerp(color1, color2, 0.5f);
// Create smooth gradients
var gradient = new ColorGradient<Hsl>(Color.Red, Color.Blue);
var colors = gradient.GetColors(10); // 10 evenly-spaced colors
Installation
dotnet add package FrameworkExtensions.System.Drawing
License
LGPL 3.0 or later - See LICENSE for details
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net6.0-windows7.0 is compatible. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net7.0-windows7.0 is compatible. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net8.0-windows7.0 is compatible. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net9.0-windows7.0 is compatible. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.1 is compatible. |
| .NET Framework | net35 is compatible. net40 is compatible. net403 was computed. net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 is compatible. net481 was computed. |
-
.NETCoreApp 3.1
- FrameworkExtensions.Backports (>= 1.0.0.212)
-
.NETFramework 3.5
- FrameworkExtensions.Backports (>= 1.0.0.212)
-
.NETFramework 4.0
- FrameworkExtensions.Backports (>= 1.0.0.212)
-
.NETFramework 4.5
- FrameworkExtensions.Backports (>= 1.0.0.212)
-
.NETFramework 4.8
- FrameworkExtensions.Backports (>= 1.0.0.212)
-
net6.0-windows7.0
- FrameworkExtensions.Backports (>= 1.0.0.212)
-
net7.0-windows7.0
- FrameworkExtensions.Backports (>= 1.0.0.212)
-
net8.0-windows7.0
- FrameworkExtensions.Backports (>= 1.0.0.212)
-
net9.0-windows7.0
- FrameworkExtensions.Backports (>= 1.0.0.212)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0.91 | 80 | 1/19/2026 |
| 1.0.0.79 | 92 | 1/5/2026 |
| 1.0.0.70 | 101 | 12/29/2025 |
| 1.0.0.55 | 181 | 12/22/2025 |
| 1.0.0.49 | 213 | 12/15/2025 |
| 1.0.0.46 | 206 | 9/29/2025 |
| 1.0.0.45 | 196 | 8/4/2025 |
| 1.0.0.37 | 191 | 7/7/2025 |
| 1.0.0.36 | 226 | 2/24/2025 |
| 1.0.0.35 | 310 | 6/24/2024 |
| 1.0.0.33 | 190 | 6/17/2024 |
| 1.0.0.31 | 194 | 6/10/2024 |
| 1.0.0.30 | 179 | 5/27/2024 |
| 1.0.0.29 | 199 | 5/6/2024 |
| 1.0.0.27 | 196 | 4/29/2024 |
| 1.0.0.25 | 208 | 4/1/2024 |
| 1.0.0.24 | 191 | 3/25/2024 |
| 1.0.0.23 | 185 | 3/5/2024 |
| 1.0.0.22 | 260 | 7/23/2023 |
| 1.0.0.21 | 236 | 7/21/2023 |
| 1.0.0.20 | 241 | 7/19/2023 |
| 1.0.0.19 | 222 | 7/19/2023 |
| 1.0.0.17 | 247 | 7/19/2023 |