亲宝软件园·资讯

展开

获取SD卡上图片和视频缩略图 Android获取SD卡上图片和视频缩略图的小例子

人气:0
想了解Android获取SD卡上图片和视频缩略图的小例子的相关内容吗,在本文为您仔细讲解获取SD卡上图片和视频缩略图的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:图片,视频,缩略图,下面大家一起来学习吧。

      如何判断文件呢? 可以通过Cursor遍历数据库,对比INTERNAL_CONTENT_URI字段的值,这是一个Uri,这里保存着Android手机SD卡上的多媒体文件完整路径。

[java]

复制代码 代码如下:

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;
                }

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;
    }

加载全部内容

相关教程
猜你喜欢
用户评论