JpegKit bridges the libjpeg-turbo C++ library into android and wraps it with an easy to use class. You can currently:
- Retrieve metadata such as width and height
- Rotate the JPEG 90, 180, or 270 degrees
- Flip the JPEG horizontally
- Flip the JPEG vertically
- Crop the JPEG to any
This is all done without decoding the JPEG to RGB. All operations on the JPEG are done in C++ space and does not touch the Java memory, allowing you to work with extremely large JPEGs without the risk of an
The State Of The Union
We've been working on a major update to the JpegKit project that we will dub
v0.3.0. This release separates concerns away from the single Jpeg class to several classes, each handling different functions of JpegKit.
In a previous release we deprecated the Jpeg class with the intention of having the new functionality ready for the spotlight.
However we discovered some bugs and issues after the initial release. Until
v0.3.0 is finalized, we've un-deprecated that Jpeg class and its other supporting classes. Below is the intended Setup and Usage for
Add JpegKit to the dependencies block in your
The core of JpegKit is the Jpeg class. When creating an object of type
Jpeg, the constructor expects a
byte. In the future you'll be able to pass just a file.
First, create a
import jpegkit.Jpeg; //... byte jpegBytes = ...; Jpeg mJpeg = new Jpeg(jpegBytes);
One can then transform this Jpeg object with the transformations listed in the Transformations section below.
After you perform your transformations, you can get a new JPEG
byte newJpegBytes = mJpeg.getJpeg();
getJpeg() call can only be used once. At this point our C++ libjpeg-turbo wrapper encodes the new JPEG and also disposes of the original and clears any other memory it used.
Transformations are performed in C++ right when you make the method call, as opposed to doing all after you finish with
getJpeg(). The transformations will be applied in the order you make the method calls.
JpegImageView is a view to display JpegKit's
JpegImageView in xml as follows.
<jpegkit.JpegImageView android:id="@+id/jpegView" android:layout_width="200dp" android:layout_height="200dp" />
Access and set the JPEG from your Activity as follows.
import jpegkit.JpegImageView; //... JpegImageView jpegView = findViewById(R.id.jpegView) jpegView.setJpeg(mJpeg);
Acceptable parameters are
Flip Horizontal or Vertical
Crop extends an
Rect cropRect = new Rect(left, top, right, bottom); mJpeg.crop(cropRect);
You can retrieve a JPEGs width, height and size. This only decodes the JPEGs header information and is very fast.
int width = mJpeg.getWidth(); int height = mJpeg.getHeight(); long size = mJpeg.getJpegSize();
JpegKit is MIT License