国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android Tiny集成圖片壓縮框架的使用

2019-10-22 18:27:18
字體:
來源:轉載
供稿:網友

為了簡化對圖片壓縮的調用,提供最簡潔與合理的api壓縮邏輯,對于壓縮為Bitmap根據屏幕分辨率動態適配最佳大小,對于壓縮為File優化底層libjpeg的壓縮,整個圖片壓縮過程全在壓縮線程池中異步壓縮,結束后分發回UI線程。

支持的壓縮類型

Tiny圖片壓縮框架支持的壓縮數據源類型:

1、Bytes
2、File
3、Bitmap
4、Stream
5、Resource
6、Uri(network、file、content)

Tiny支持單個數據源壓縮以及批量壓縮,支持的壓縮類型:

1、數據源—>壓縮為Bitmap
2、數據源—>壓縮為File
3、數據源—>壓縮為File并返回壓縮后的Bitmap
4、批量數據源—>批量壓縮為Bitmap
5、批量數據源—>批量壓縮為File
6、批量數據源—>批量壓縮為File并返回壓縮后Bitmap

壓縮參數

Tiny.BitmapCompressOptions

Bitmap壓縮參數可配置三個:

1、width
2、height
3、Bitmap.Config

如果不配置,Tiny內部會根據屏幕動態適配以及默認使用ARGB_8888

Tiny.FileCompressOptions

File壓縮參數可配置四個:

1、quality-壓縮質量,默認為76
2、isKeepSampling-是否保持原數據源圖片的寬高
3、fileSize-壓縮后文件大小
4、outfile-壓縮后文件存儲路徑

如果不配置,Tiny內部會根據默認壓縮質量進行壓縮,壓縮后文件默認存儲在:ExternalStorage/Android/data/${packageName}/tiny/目錄下

Tiny項目地址: https://github.com/tianyingzhong/Tiny

Tiny與微信朋友圈的壓縮率比較

下面是使用Tiny圖片壓縮庫進行壓縮的效果對比示例:

 

圖片信息 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)

 

壓縮為Bitmap

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  }});

壓縮為File 

 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  }});

壓縮為File并返回Bitmap

 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  }});

批量壓縮為Bitmap

 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  }});

批量壓縮為File

 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  }});

批量壓縮為File并返回Bitmap

 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  }});

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 兴安盟| 嵊泗县| 远安县| 都江堰市| 新干县| 台南市| 吉安县| 关岭| 青神县| 沁水县| 无棣县| 台湾省| 潼南县| 宜宾市| 襄汾县| 南陵县| 星子县| 江津市| 博客| 青龙| 合山市| 凤翔县| 平邑县| 碌曲县| 股票| 新丰县| 基隆市| 磐安县| 南平市| 临江市| 平安县| 长乐市| 南郑县| 湘乡市| 岑溪市| 都兰县| 唐河县| 宣城市| 崇文区| 当雄县| 霍林郭勒市|