Giter Club home page Giter Club logo

mozjpeg-wrapper's Introduction

MozJpeg-wrapper

The most complete MozJpeg .NET wrapper in pure managed C#.

Exposes decoding API, encoding API and information API via turbojpeg-compatible API info for any JPEG file). In the future I'll update to expose more advanced Decoding API.

The wrapper is in safe managed code in one class. No need for external dll except turbojpeg_x86.dll and turbojpeg_x64.dll (included v3.2). The wrapper work in 32, 64 bit or ANY system (automatic select the apropiate library).

The code is fully commented and includes a simple example for using the wrapper.

Use

Load JPEG image for JPEG file

using (MozJpeg mozJpeg = new MozJpeg())
	this.pictureBox.Image = mozJpeg.Load(pathFileName);

Save bitmap to JPEG file with quality 85

using (MozJpeg mozJpeg = new MozJpeg())
	mozJpeg.Save(bmp, fileName, 85);

Decode JPEG date in byte array to bitmap and load in PictureBox container

byte[] rawJpeg = File.ReadAllBytes("test.jpg");
using (clsWebP mozJpeg = new rawJpeg())
	  this.pictureBox.Image = mozJpeg.Decode(rawJpeg);

Encode bitmap to byte array with quality 75, without JFIF, with accurate DCT, optimized scan and tuned for MS-SSIM (maximum compression and minimum size)

byte[] rawJpeg;
using (MozJpeg mozJpeg = new MozJpeg())
		rawJpeg = mozJpeg.Encode(bmp, 75, false, TJFlags.ACCURATEDCT |
		                         TJFlags.DC_SCAN_OPT2 | TJFlags.TUNE_MS_SSIM);
File.WriteAllBytes("test.webp", rawJpeg);

Get info from JPEG file

byte[] rawJpeg = File.ReadAllBytes("test.jpg");
using (clsWebP mozJpeg = new rawJpeg())
		mozJpeg.GetInfo(rawJpeg, out width, out height, out horizontalResolution,
		                out verticalResolution, out subsampl, out colorspace);

Thanks to pornel for his amazing code.

Without his work this wrapper would not have been possible.

mozjpeg-wrapper's People

Contributors

josepineiro avatar tps avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.