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

首頁(yè) > 系統(tǒng) > Android > 正文

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

2019-12-12 02:00:27
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

為了簡(jiǎn)化對(duì)圖片壓縮的調(diào)用,提供最簡(jiǎn)潔與合理的api壓縮邏輯,對(duì)于壓縮為Bitmap根據(jù)屏幕分辨率動(dòng)態(tài)適配最佳大小,對(duì)于壓縮為File優(yōu)化底層libjpeg的壓縮,整個(gè)圖片壓縮過(guò)程全在壓縮線程池中異步壓縮,結(jié)束后分發(fā)回UI線程。

支持的壓縮類(lèi)型

Tiny圖片壓縮框架支持的壓縮數(shù)據(jù)源類(lèi)型:

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

Tiny支持單個(gè)數(shù)據(jù)源壓縮以及批量壓縮,支持的壓縮類(lèi)型:

1、數(shù)據(jù)源―>壓縮為Bitmap
2、數(shù)據(jù)源―>壓縮為File
3、數(shù)據(jù)源―>壓縮為File并返回壓縮后的Bitmap
4、批量數(shù)據(jù)源―>批量壓縮為Bitmap
5、批量數(shù)據(jù)源―>批量壓縮為File
6、批量數(shù)據(jù)源―>批量壓縮為File并返回壓縮后Bitmap

壓縮參數(shù)

Tiny.BitmapCompressOptions

Bitmap壓縮參數(shù)可配置三個(gè):

1、width
2、height
3、Bitmap.Config

如果不配置,Tiny內(nèi)部會(huì)根據(jù)屏幕動(dòng)態(tài)適配以及默認(rèn)使用ARGB_8888

Tiny.FileCompressOptions

File壓縮參數(shù)可配置四個(gè):

1、quality-壓縮質(zhì)量,默認(rèn)為76
2、isKeepSampling-是否保持原數(shù)據(jù)源圖片的寬高
3、fileSize-壓縮后文件大小
4、outfile-壓縮后文件存儲(chǔ)路徑

如果不配置,Tiny內(nèi)部會(huì)根據(jù)默認(rèn)壓縮質(zhì)量進(jìn)行壓縮,壓縮后文件默認(rèn)存儲(chǔ)在:ExternalStorage/Android/data/${packageName}/tiny/目錄下

Tiny項(xiàng)目地址: https://github.com/tianyingzhong/Tiny

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

下面是使用Tiny圖片壓縮庫(kù)進(jìn)行壓縮的效果對(duì)比示例:

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

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 山阳县| 吕梁市| 塘沽区| 航空| 慈利县| 南昌市| 贺兰县| 米脂县| 靖江市| 罗江县| 巴林右旗| 黄大仙区| 杂多县| 昌邑市| 武安市| 江油市| 卢龙县| 罗源县| 孟州市| 招远市| 镇原县| 迭部县| 伊吾县| 波密县| 台湾省| 滁州市| 兴国县| 涟源市| 闵行区| 盐池县| 汨罗市| 万全县| 岐山县| 如皋市| 随州市| 齐河县| 阿拉善左旗| 邓州市| 弥渡县| 新昌县| 绵阳市|