需要快速提取圖片和影片縮圖可以直接存取 android.provider.MediaStore.Images.Thumbnails 和android.provider.MediaStore.Video.Thumbnails這兩個資料庫,即可查詢出來縮圖 。
如何判斷檔案呢? 可以通過Cursor遍曆資料庫,對比INTERNAL_CONTENT_URI欄位的值,這是一個Uri,這裡儲存著Android手機SD卡上的多媒體檔案完整路徑。
Uri originalUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
//若為視頻則為MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
ContentResolver cr = this.getContentResolver();
Cursor cursor = cr.query(originalUri, null, null, null, null);
if (cursor == null) {
return;
}
for (cursor.moveToFirst();!cursor.isAfterLast(); cursor.moveToNext()) {
long thumbNailsId = cursor.getLong(cursor .getColumnIndex("_ID"));
Bitmap bitmap = MediaStore.Images.Thumbnails.getThumbnail(cr,
thumbNailsId, Video.Thumbnails.MICRO_KIND, null);
//若為視頻則為
// Bitmap bitmap = MediaStore.Video.Thumbnails.getThumbnail(cr,
// thumbNailsId, Video.Thumbnails.MICRO_KIND, null);
return bitmap;
}