an image compression framework.(一个高保真、高压缩比的图片压缩框架)
an image compression framework.
Blog entry with introduction or Introduction of compression
| ImageInfo | Tiny | Wechat | | :-: | :-: | :-: | 6.66MB (3500x2156) | 151KB (1280x788) | 135KB (1280x788)| 4.28MB (4160x3120) | 219KB (1280x960)| 195KB (1280x960)| 2.60MB (4032x3024) | 193KB (1280x960)| 173KB (1280x960)| 372KB (500x500) | 38.67KB (500x500) | 34.05KB (500x500)| 236KB (960x1280) | 127KB (960x1280) | 118KB (960x1280)|
Tinydoes not depend on any library , it keeps the code clean on architecture .
Tinyalso uses an asynchronous thread pool to compress images , and will hand out the result in the main thread when compression is completed.
implementation 'com.zxy.android:tiny:1.1.0'
Tiny provide abi:
armeabi、
armeabi-v7a、
arm64-v8a、
x86.
Choose what you need "abi" version:
android { defaultConfig { ndk { abiFilters 'armeabi','x86'//or armeabi-v7a、arm64-v8a、x86 } } }
Tiny.getInstance().init(this);
Tiny.BitmapCompressOptions options = new Tiny.BitmapCompressOptions(); //options.height = xxx;//some compression configuration. Tiny.getInstance().source("").asBitmap().withOptions(options).compress(new BitmapCallback() { @Override public void callback(boolean isSuccess, Bitmap bitmap, Throwable t) { //return the compressed bitmap object } });//or sync compress. BitmapResult result = Tiny.getInstance().source("").asBitmap().withOptions(options).compressSync();
Tiny.FileCompressOptions options = new Tiny.FileCompressOptions(); Tiny.getInstance().source("").asFile().withOptions(options).compress(new FileCallback() { @Override public void callback(boolean isSuccess, String outfile, Throwable t) { //return the compressed file path } });//or sync compress. FileResult result = Tiny.getInstance().source("").asFile().withOptions(options).compressSync();
Tiny.FileCompressOptions options = new Tiny.FileCompressOptions(); Tiny.getInstance().source("").asFile().withOptions(options).compress(new FileWithBitmapCallback() { @Override public void callback(boolean isSuccess, Bitmap bitmap, String outfile, Throwable t) { //return the compressed file path and bitmap object } });//or sync compress. FileWithBitmapResult result = Tiny.getInstance().source("").asFile().withOptions(options).compressWithReturnBitmapSync();
Tiny.BitmapCompressOptions options = new Tiny.BitmapCompressOptions(); Tiny.getInstance().source("").batchAsBitmap().withOptions(options).batchCompress(new BitmapBatchCallback() { @Override public void callback(boolean isSuccess, Bitmap[] bitmaps, Throwable t) { //return the batch compressed bitmap object } });//or sync compress. BitmapBatchResult result = Tiny.getInstance().source("").batchAsBitmap().withOptions(options).batchCompressSync();
Tiny.FileCompressOptions options = new Tiny.FileCompressOptions(); Tiny.getInstance().source("").batchAsFile().withOptions(options).batchCompress(new FileBatchCallback() { @Override public void callback(boolean isSuccess, String[] outfile, Throwable t) { //return the batch compressed file path } });//or sync compress. FileBatchResult result = Tiny.getInstance().source("").batchAsFile().withOptions(options).batchCompressSync();
Tiny.FileCompressOptions options = new Tiny.FileCompressOptions(); Tiny.getInstance().source("").batchAsFile().withOptions(options).batchCompress(new FileWithBitmapBatchCallback() { @Override public void callback(boolean isSuccess, Bitmap[] bitmaps, String[] outfile, Throwable t) { //return the batch compressed file path and bitmap object } });//or sync compress. FileWithBitmapBatchResult result = Tiny.getInstance().source("").batchAsFile().withOptions(options).batchCompressWithReturnBitmapResult();
libtiny.so
{@link FileCompressOptions#overrideSource}, and setting up the batch compressed file paths—see
{@link BatchFileCompressOptions#outfiles}
{@link Tiny#clearCompressDirectory}
Throwableparameter to the callback method
{@link xxxxCallback#callback}, see Update Introduce
Apache LicenseVersion 2.0, January 2004 http://www.apache.org/licenses/
Copyright 2018 郑晓勇
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.0Unless 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.