Android的圖片壓縮類ThumbnailUtils

來源:互聯網
上載者:User

從Android 2.2開始系統新增了一個縮圖ThumbnailUtils類,位於framework包下的android.media.ThumbnailUtils位置,可以協助我們從mediaprovider中擷取系統中的視頻或圖片檔案的縮圖,該類提供了三種靜態方法可以直接調用擷取。
 
 
1、extractThumbnail (source, width, height):
 
 
Java代碼 
/**
 * 
 * 建立一個指定大小的縮圖
 * @param source 源檔案(Bitmap類型)
 * @param width  壓縮成的寬度
 * @param height 壓縮成的高度
 */ 
ThumbnailUtils.extractThumbnail(source, width, height); 
 
2、extractThumbnail(source, width, height, options):
 
 
Java代碼 
/**
 * 建立一個指定大小置中的縮圖
 * 
 * @param source 源檔案(Bitmap類型)
 * @param width  輸出縮圖的寬度
 * @param height 輸出縮圖的高度
 * @param options 如果options定義為OPTIONS_RECYCLE_INPUT,則回收@param source這個資源檔
 * (除非縮圖等於@param source)
 * 
 */ 
 ThumbnailUtils.extractThumbnail(source, width, height, options); 
 
 
3、createVideoThumbnail(filePath, kind):
 
 
Java代碼 
/**
 * 建立一張視頻的縮圖
 * 如果視頻已損壞或者格式不支援可能返回null
 * 
 * @param filePath 視頻檔案路徑  如:/sdcard/android.3gp
 * @param kind kind可以為MINI_KIND或MICRO_KIND
 * 
 */ 
ThumbnailUtils.createVideoThumbnail(filePath, kind); 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.