JPEG decoder for .NET Core

Some of you might already know that there is “currently” not any built in default JPEG decoder class for .NET Core since System.Drawing (except for System.Drawing.Primitives) is currently not present as a Nuget package.

So is there any way of DECODING JPEG pictures on .NET Core for some server side processing?

Yes certainly there is!

All you need to do is to download a Nuget package called ImageProcessor 2.4.4 which you can find here for full .NET Framework

Is it available for .Net Core?

Yes it is! It is only on MyGet for the time being. That is hosted here.

Any type supported apart from JPEG?
Yes.

Encoding/decoding of image formats (plugable):
1. Jpeg (Includes Subsampling. Progressive writing required)
2. Bmp (Read: 32bit, 24bit, 16 bit. Write: 32bit, 24bit just now)
3. Png (Read: Rgb, Rgba, Grayscale, Grayscale + alpha, Palette. Write: Rgb, Rgba, Grayscale, 4. Grayscale + alpha, Palette) Needs interlaced decoding #379
5. Gif (Includes animated)

Some of basic samples are as below:

Sample 1:

// resizing and filter (grayscale)
using (FileStream stream = File.OpenRead(“foo.jpg”))
using (FileStream output = File.OpenWrite(“bar.jpg”))
{
Image image = new Image(stream);
image.Resize(image.Width / 2, image.Height / 2)
.Grayscale()
.Save(output);
}

Sample 2: Accessing Pixels

Image image = new Image(400, 400);
using (PixelAccessor<Color, uint> pixels = image.Lock())
{
pixels[200, 200] = Color.White;
}

You can find more advantages of this Nuget package here.

Thanks James Jackson-South for building this.

Happy coding!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s