An Android library to bring your ordinary photos to life with an awesome crystallized effect.
- Introduction
- Lowpoly Samples
- Installation
- Library Details
- Usage Examples
- Critical Analysis
- Sample App
- How to Contribute
- About the Author
- License
RxLowpoly serves as an improvement over XLowPoly by
- fixing out of memory crashes by scaling down the image in a loss-less manner before processing.
- providing better quality results by using
4000
as the point count by default which provides a good trade-off between speed and time. - the higher point count leads to a longer execution period, but it is significantly reduced by scaling down the image before processing.
- provides wider choice of input sources like
Bitmap
,File
,Uri
orDrawable resource
. - natively using
RxJava
for background processing thereby reducing boilerplate code on the developer's end.
Original Image | Lowpoly Image |
---|---|
Add the dependency in your app module's build.gradle file
dependencies {
...
implementation "com.zebrostudio.rxlowpoly:rxlowpoly:{latest_version}"
}
That's it!
- RxLowpoly uses JNI with 64 bit support to meet google specified requirement for all apps to be 64 bit enabled by August 2019.
- Use of JNI enables much faster execution than other similar libraries.
- Use of Sobel Operator for edge detection.
- Use of Delaunay Triangulation on the result from the sobel operator to construct the final crystallized lowpoly effect on the image.
RxLowpoly uses the Java Native Interface to run native code written in C
which provides much faster processing for edge detection using the Sobel Operator and then implementing the Delaunay Triangulation algorithm.
The Sobel Edge Detector is a gradient based edge detection algorithm which provides us with separate planes on which the Delaunay Triangulation can be applied.
We take a set P of discrete points on an image plane and apply Delaunay Triangulation DT(P) to produce triangles connecting 3 points at a time such that no point in **P **is inside the circum-circle of any triangle in DT(P). These separate triangles taken together in-turn provide us with the image having a crystallized effect.
Which leads to the resultant crystallized image as :-
-
The most simple use case is :-
RxLowpoly.with(context) .input(bitmap) .generateAsync()
Along with
Bitmaps
we can also useDrawables
orFiles
orUri
as input. -
When we need to downscale the image :-
RxLowpoly.with(context) .input(bitmap) .overrideScaling(downScalingFactor) .generateAsync()
-
When we need to set a maximum width for the image :-
RxLowpoly.with(context) .input(bitmap) .overrideScaling(maxWidth) .generateAsync()
-
We can also set a quality for the lowpoly image :-
RxLowpoly.with(context) .input(inputUri) .overrideScaling(downScalingFactor) .quality(Quality.HIGH) .generateAsync()
VERY_HIGH
,MEDIUM
,LOW
andVERY_LOW
are also available as Quality configurations -
To save the lowpoly image to a file :-
RxLowpoly.with(context) .input(inputUri) .overrideScaling(downScalingFactor) .quality(Quality.HIGH) .output(outputFile) // An Uri of a File is also supported as an output destination .generateAsync()
All asynchronous operation is done on the IO scheduler
.
Replacing generateAsync()
with generate()
in each of the Asynchronous call examples leads to a synchronous call with a lowpoly Bitmap
as a result.
A Bitmap
of the generated lowpoly image is always returned irrespective of synchronous or asynchronous calls and whether an output File
or Uri
is supplied using the output
method.
Note : A full implementation can be found in the app module of this repository or in the open sourced WallR app.
The following tests have been performed on a Xiaomi Redmi Note 5 Pro with 6 gb Ram.
Thus it is evident that when quality is set to High
, a good trade-off between speed and texture is obtained, hence the default value of Quality
is set to HIGH
.
Also, we can see that Bitmap
is the input format of choice as it is processed the fastest, followed by Uri
, File
and Drawable
respectively.
The sample app provides an implementation of various configurations of RxLowpoly
which one can experience and assess first hand before using the library.
Please feel free to raise an issue in-case you come across a bug or even if you have any minor suggestion.
Android Developer with 2 years of experience in building apps that look and feel great. Enthusiastic towards writing clean and maintainable code. Open source contributor.
Copyright 2019 Abhriya Roy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.