RotSpriteSharp.SystemDrawingExtensions
1.0.1
dotnet add package RotSpriteSharp.SystemDrawingExtensions --version 1.0.1
NuGet\Install-Package RotSpriteSharp.SystemDrawingExtensions -Version 1.0.1
<PackageReference Include="RotSpriteSharp.SystemDrawingExtensions" Version="1.0.1" />
<PackageVersion Include="RotSpriteSharp.SystemDrawingExtensions" Version="1.0.1" />
<PackageReference Include="RotSpriteSharp.SystemDrawingExtensions" />
paket add RotSpriteSharp.SystemDrawingExtensions --version 1.0.1
#r "nuget: RotSpriteSharp.SystemDrawingExtensions, 1.0.1"
#:package RotSpriteSharp.SystemDrawingExtensions@1.0.1
#addin nuget:?package=RotSpriteSharp.SystemDrawingExtensions&version=1.0.1
#tool nuget:?package=RotSpriteSharp.SystemDrawingExtensions&version=1.0.1
RotSpriteSharp (.NET port)
This is a port of the rotsprite-rs Rust library, which implements the RotSprite algorithm for high-quality pixel art rotation. The port aims to faithfully reproduce the original algorithm and provide a demo for batch rotation and comparison. It supports all currently supported .NET LTS versions.
RotSpriteSharp is a stable library. Future updates will mainly address dependency upgrades, support for new .NET LTS releases, and occasional new extensions. The core algorithm is complete and production-ready.
.NET LTS Support Timetable
| Version | Release Date | End of Support |
|---|---|---|
| .NET 8 | Nov 2023 | Nov 2026 |
| .NET 10 | Nov 2025 | Nov 2028 |
For more details, see the official .NET support policy.
About RotSpriteSharp
RotSpriteSharp is a pixel art rotation algorithm that preserves sharpness and detail, outperforming standard aliased rotation methods for sprites and pixel art. It works by:
- Pixel-Guessing Enlargement: Scales the input image up by 8x using a custom algorithm inspired by Scale2x, checking for pixel similarity rather than equality.
- Optimal Rotation Offset: Searches for the best rotation offset by iterating over a small grid, rotating the enlarged image, and choosing the offset with minimal color difference.
- Aliased Rotation & Downscaling: Rotates and scales the image back to the original size using nearest-neighbor methods.
- Single-Pixel Detail Correction: Optionally post-processes the output to fix overlooked single-pixel details.
This approach uses pixel-level heuristics to approximate high-quality rotation, resulting in visually pleasing, sharp, and smooth rotated sprites.
Usage
You can run the demo project (RotCon) with command-line parameters:
RotCon.exe <inputPath> [outputDir] [angles]
inputPath: Path to the input image (default:threeforms.png)outputDir: Optional output directory for results (default: current directory)angles: Optional comma-separated list of rotation angles (default:0,45,90,135,180,225,270,315)
Example:
RotCon.exe threeforms.png out 0,90,180,270
This will output rotated images using the RotSpriteSharp algorithm, saving them in the out directory as threeforms_rot0.png, threeforms_rot90.png, etc.
Library API Example
The core rotation API is provided by the RotSpriteSharp class:
using RotSpriteSharp;
using SixLabors.ImageSharp.PixelFormats;
// Load your pixel buffer (e.g., from ImageSharp)
Rgba32[] pixels = ...;
int width = ...;
double angle = 45.0;
Rgba32 emptyColor = new Rgba32(0, 0, 0, 0);
// Rotate the image
var rotated = RotSpriteSharp.Rotate(pixels, emptyColor, width, angle);
// rotated.Pixels, rotated.Width, rotated.Height
- For angles divisible by 90, the algorithm uses a fast path (no upscaling).
- For other angles, the image is upscaled by 8x, rotated, and downscaled for high-quality results.
Extension Projects & Usage
RotSpriteSharp provides extension libraries for popular graphics APIs:
SkiaSharp Extensions
Add a reference to RotSpriteSharp.SkiaSharpExtensions and use:
using RotSpriteSharp.SkiaSharpExtensions;
using SkiaSharp;
// Rotate a SKBitmap
SKBitmap bitmap = ...;
SKBitmap rotated = bitmap.RotateWithRotSprite(45);
// Rotate a SKColor[] pixel buffer
SKColor[] pixels = ...;
int width = ...;
SKColor[] rotatedPixels = pixels.RotateWithRotSprite(width, 45);
System.Drawing Extensions
Add a reference to RotSpriteSharp.SystemDrawingExtensions and use (Windows only):
using RotSpriteSharp.SystemDrawingExtensions;
using System.Drawing;
// Rotate a Bitmap
Bitmap bitmap = ...;
Bitmap rotated = bitmap.RotateWithRotSprite(45);
// Rotate a Color[] pixel buffer
Color[] pixels = ...;
int width = ...;
Color[] rotatedPixels = pixels.RotateWithRotSprite(width, 45);
Note: System.Drawing.Common is only supported on Windows. The extension methods will throw
PlatformNotSupportedExceptionon other platforms.
Projects
RotSpriteSharp: Core library implementing the algorithm (no external dependencies).RotCon: Console demo for batch rotation and comparison (uses SkiaSharp for image loading and saving).
Requirements
- All currently supported .NET LTS versions
- SkiaSharp (only required for the
RotCondemo application)
Attribution & Credits
- Original RotSprite algorithm by Xenowhirl
- Rust implementation by tversteeg/rotsprite
- Pixel Art by Redshrike
This .NET port is based on the Rust implementation and strives to maintain algorithmic fidelity with the original RotSprite algorithm. For more details on the algorithm, see the RotSprite Wikipedia page and the Rust implementation.
License
See LICENSE file for details. This project is licensed under the AGPL-3.0-or-later, following the original Rust implementation.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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. 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. net10.0 is compatible. 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. |
-
net10.0
- RotSpriteSharp (>= 1.0.1)
- System.Drawing.Common (>= 9.0.10)
-
net8.0
- RotSpriteSharp (>= 1.0.1)
- System.Drawing.Common (>= 9.0.10)
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.1 | 219 | 11/9/2025 |
| 1.0.1-beta.13 | 168 | 11/9/2025 |
| 1.0.0 | 145 | 11/8/2025 |