Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
您现在的位置: Android教程網 >> Android系統教程 >  >> Android 技術 >> Android 開發 >> 進階開發

ThumbnailUtils:Android 2.2 的縮圖產生器

編輯:進階開發

從 Android 2.2 起,framework 新增了一個 ThumbnailUtils 類別,位置在 android.media.ThumbnailUtils。它能直接從 media provider 取得系統中影片或圖片檔案的縮圖,省下自己解碼裁切的功夫。類別提供三個靜態方法可直接呼叫。

static Bitmap createVideoThumbnail(String filePath, int kind)
為影片檔產生縮圖。第一個參數是影片路徑,例如 /sdcard/android123.3gp;第二個參數可為 MINI_KIND 或 MICRO_KIND,最終尺寸與解析度有關。

static Bitmap extractThumbnail(Bitmap source, int width, int height, int options)
直接對現成的 Bitmap 做縮圖,最後的 options 可帶入 OPTIONS_RECYCLE_INPUT 以回收原始 Bitmap 的資源,在記憶體吃緊時很有用。

static Bitmap extractThumbnail(Bitmap source, int width, int height)
與上一個相同,只是沒有 options 參數。

要留意的是,ThumbnailUtils 從 API Level 8 起才支援,向下相容時得先檢查版本。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved