当前位置:网站首页 > 科技动态 > 正文

图片压缩脚本

an image compression framework.


Download Travis Hex.pm

Blog entry with introduction or Introduction of compression

Effect of compression

ImageInfo Tiny Wechat
6.66MB (3500x2156) 151KB (1280x788) 135KB (1280x789)
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)

Introduce

Tiny does not depend on any library , it keeps the code clean on architecture . Tiny also uses asynchronous thread pool to compress image , and will hand out the result in the main thread when compression is completed.

Usage

Installation

compile 'com.zxy.android:tiny:${LAST_VERSION}' 

Choose an abi

Tiny provide abi:armeabiarmeabi-v7aarm64-v8ax86.

Choose what you need "abi" version:

android { defaultConfig { ndk { abiFilters 'armeabi-v7a','x86'//or armeabi、arm64-v8a、x86 } } } 

Initialization

Tiny.getInstance().init(this); 

Compression

AsBitmap

 Tiny.BitmapCompressOptions options = new Tiny.BitmapCompressOptions(); Tiny.getInstance().source("").asBitmap().withOptions(options).compress(new BitmapCallback() { @Override public void callback(boolean isSuccess, Bitmap bitmap) { //return the compressed bitmap object } }); 

AsFile

 Tiny.FileCompressOptions options = new Tiny.FileCompressOptions(); Tiny.getInstance().source("").asFile().withOptions(options).compress(new FileCallback() { @Override public void callback(boolean isSuccess, String outfile) { //return the compressed file path } }); 

AsFileWithReturnBitmap

 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) { //return the compressed file path and bitmap object } }); 

BatchAsBitmap

 Tiny.BitmapCompressOptions options = new Tiny.BitmapCompressOptions(); Tiny.getInstance().source("").batchAsBitmap().withOptions(options).batchCompress(new BitmapBatchCallback() { @Override public void callback(boolean isSuccess, Bitmap[] bitmaps) { //return the batch compressed bitmap object } }); 

BatchAsFile

 Tiny.FileCompressOptions options = new Tiny.FileCompressOptions(); Tiny.getInstance().source("").batchAsFile().withOptions(options).batchCompress(new FileBatchCallback() { @Override public void callback(boolean isSuccess, String[] outfile) { //return the batch compressed file path } }); 

BatchAsFileWithReturnBitmap

 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) { //return the batch compressed file path and bitmap object } }); 

License

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ Copyright 2017 郑晓勇 

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.

版权声明


相关文章:

  • react hooks项目2025-09-04 18:30:01
  • 服务治理的质量保证与测试策略是什么2025-09-04 18:30:01
  • 如何编写vscode插件2025-09-04 18:30:01
  • 低功耗模块2025-09-04 18:30:01
  • 反向传播算法的作用是什么?2025-09-04 18:30:01
  • romberg测试2025-09-04 18:30:01
  • 成都公交老年卡年检2025-09-04 18:30:01
  • java jdk怎么用2025-09-04 18:30:01
  • mac如何点击右键2025-09-04 18:30:01
  • android开发步骤2025-09-04 18:30:01