AndroidTiny集成圖片壓縮框架的使用

為了簡(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線程。

創(chuàng)新互聯(lián)建站是一家從事企業(yè)網(wǎng)站建設(shè)、網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、行業(yè)門戶網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)制作的專業(yè)的建站公司,擁有經(jīng)驗(yàn)豐富的網(wǎng)站建設(shè)工程師和網(wǎng)頁(yè)設(shè)計(jì)人員,具備各種規(guī)模與類型網(wǎng)站建設(shè)的實(shí)力,在網(wǎng)站建設(shè)領(lǐng)域樹立了自己獨(dú)特的設(shè)計(jì)風(fēng)格。自公司成立以來(lái)曾獨(dú)立設(shè)計(jì)制作的站點(diǎn)近1000家。

支持的壓縮類型

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

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

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

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ì)比示例:

圖片信息TinyWechat
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í)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。

網(wǎng)頁(yè)標(biāo)題:AndroidTiny集成圖片壓縮框架的使用
轉(zhuǎn)載源于:http://muchs.cn/article48/iepohp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化網(wǎng)站設(shè)計(jì)公司、移動(dòng)網(wǎng)站建設(shè)網(wǎng)站內(nèi)鏈、網(wǎng)頁(yè)設(shè)計(jì)公司、品牌網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)