CoreJ2K.ImageSharp
1.0.1
dotnet add package CoreJ2K.ImageSharp --version 1.0.1
NuGet\Install-Package CoreJ2K.ImageSharp -Version 1.0.1
<PackageReference Include="CoreJ2K.ImageSharp" Version="1.0.1" />
<PackageVersion Include="CoreJ2K.ImageSharp" Version="1.0.1" />
<PackageReference Include="CoreJ2K.ImageSharp" />
paket add CoreJ2K.ImageSharp --version 1.0.1
#r "nuget: CoreJ2K.ImageSharp, 1.0.1"
#:package CoreJ2K.ImageSharp@1.0.1
#addin nuget:?package=CoreJ2K.ImageSharp&version=1.0.1
#tool nuget:?package=CoreJ2K.ImageSharp&version=1.0.1
CoreJ2K.ImageSharp - A Cross-Platform JPEG2000 Codec
Copyright (c) 1999-2000 JJ2000 Partners; Copyright (c) 2007-2012 Jason S. Clary; Copyright (c) 2013-2016 Anders Gustafsson, Cureos AB; Copyright (c) 2024-2025 Sjofn LLC; Copyright (c) 2025 Mistial Developer.
Licensed and distributable under the terms of the BSD license
Summary
CoreJ2K.ImageSharp is a cross-platform JPEG2000 codec for .NET Standard 2.0/2.1 applications. Originally based on CSJ2K (a C# port of the Java jj2000 package), this implementation exclusively uses SixLabors.ImageSharp for image handling, providing consistent behavior across all platforms without Windows-specific dependencies.
Installation
Install via NuGet Package Manager:
Install-Package CoreJ2K.ImageSharp
Or using the .NET CLI:
dotnet add package CoreJ2K.ImageSharp
Usage
Setup
First, register ImageSharp support in your application:
using CoreJ2K.ImageSharp;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
// Register ImageSharp support (call once at startup)
ImageSharpImageCreator.Register();
Decoding
To decode a JPEG 2000 encoded image:
using CoreJ2K;
// From file
var decodedImage = J2kImage.FromFile("image.jp2");
// From stream
var decodedImage = J2kImage.FromStream(stream);
// From byte array
var decodedImage = J2kImage.FromBytes(jpegData);
The returned PortableImage
can be cast to ImageSharp types:
// Cast to specific ImageSharp pixel formats
var rgbaImage = decodedImage.As<Image<Rgba32>>();
var rgbImage = decodedImage.As<Image<Rgb24>>();
var grayImage = decodedImage.As<Image<L8>>();
var grayAlphaImage = decodedImage.As<Image<La16>>();
Encoding
To encode an ImageSharp image to JPEG2000:
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
// Load or create an ImageSharp image
var image = Image.Load<Rgba32>("input.png");
// Encode to JPEG2000 bytes
byte[] jp2Data = J2kImage.ToBytes(image);
// Encode with custom parameters
var parameters = new ParameterList();
parameters["rate"] = "2.0"; // Compression ratio
byte[] jp2Data = J2kImage.ToBytes(image, parameters);
Alternative Input Sources
For specialized formats, you can also create encodable sources from streams:
// From PGM/PPM streams
var source = J2kImage.CreateEncodableSource(stream);
byte[] jp2Data = J2kImage.ToBytes(source);
// From multiple PGX component streams
var componentStreams = new List<Stream> { stream1, stream2, stream3 };
var source = J2kImage.CreateEncodableSource(componentStreams);
byte[] jp2Data = J2kImage.ToBytes(source);
ROI (Region of Interest) Support
CoreJ2K.ImageSharp supports ROI encoding using the Maxshift method, allowing you to prioritize specific regions of an image during compression. This ensures that important areas maintain higher quality even at lower bitrates.
Basic ROI encoding example:
// Create encoding parameters with a rectangular ROI
var parameters = new ParameterList();
parameters["Rroi"] = "R 100 100 200 150"; // Rectangle at (100,100) with width=200, height=150
parameters["rate"] = "1.0"; // Target bitrate
// Encode with ROI
byte[] encodedData = J2kImage.ToBytes(image, parameters);
Facial detection ROI example (68-point landmarks):
// Define 3 regions for facial encoding
// Region 1: Eyes & eyebrows (highest priority)
// Region 2: Nose, mouth & jaw (medium priority)
// Region 3: Full face with context (standard compression)
parameters["Rroi"] = "R 180 190 150 60 R 170 250 170 150 R 120 150 280 300";
parameters["Ralign"] = "on"; // Better performance with aligned blocks
For detailed ROI documentation including all supported shapes and parameters, see docs/ROI_ENCODING.md. For complete facial detection examples, see Examples/FacialDetectionROIExample.cs.
Resources
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. 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. 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. 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 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 | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- CoreJ2K (>= 1.1.2.50)
- JetBrains.Annotations (>= 2025.2.0)
- SixLabors.ImageSharp (>= 2.1.10)
-
.NETStandard 2.1
- CoreJ2K (>= 1.1.2.50)
- JetBrains.Annotations (>= 2025.2.0)
- SixLabors.ImageSharp (>= 2.1.10)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Added JetBrains.Annotations support and resolved NotImplementedException for multi-component images. Updated to use NuGet CoreJ2K dependency.