麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 系統 > Android > 正文

android 獲取視頻,圖片縮略圖的具體實現

2020-04-11 12:13:09
字體:
來源:轉載
供稿:網友

1、獲取視頻縮略圖有兩個方法(1)通過內容提供器來獲取(2)人為創建縮略圖

(1)缺點就是必須更新媒體庫才能看到最新的視頻的縮略圖

[java]

復制代碼 代碼如下:

/**
     * @param context
     * @param cr
     * @param Videopath
     * @return
     */
    public static Bitmap getVideoThumbnail(Context context, ContentResolver cr, String Videopath) { 
            ContentResolver testcr = context.getContentResolver(); 
            String[] projection = { MediaStore.Video.Media.DATA, MediaStore.Video.Media._ID, }; 
            String whereClause = MediaStore.Video.Media.DATA + " = '" + Videopath + "'"; 
            Cursor cursor = testcr.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, projection, whereClause, 
                            null, null); 
            int _id = 0; 
            String videoPath = ""; 
            if (cursor == null || cursor.getCount() == 0) { 
                    return null; 
            } 
            if (cursor.moveToFirst()) { 

                    int _idColumn = cursor.getColumnIndex(MediaStore.Video.Media._ID); 
                    int _dataColumn = cursor.getColumnIndex(MediaStore.Video.Media.DATA); 
                    do { 
                            _id = cursor.getInt(_idColumn); 
                            videoPath = cursor.getString(_dataColumn); 
                    } while (cursor.moveToNext()); 
            } 
            cursor.close();
            BitmapFactory.Options options = new BitmapFactory.Options(); 
            options.inDither = false; 
            options.inPreferredConfig = Bitmap.Config.RGB_565; 
            Bitmap bitmap = MediaStore.Video.Thumbnails.getThumbnail(cr, _id, Images.Thumbnails.MINI_KIND, 
                            options); 
            return bitmap; 
    }

/**
     * @param context
     * @param cr
     * @param Videopath
     * @return
     */
    public static Bitmap getVideoThumbnail(Context context, ContentResolver cr, String Videopath) {
            ContentResolver testcr = context.getContentResolver();
            String[] projection = { MediaStore.Video.Media.DATA, MediaStore.Video.Media._ID, };
            String whereClause = MediaStore.Video.Media.DATA + " = '" + Videopath + "'";
            Cursor cursor = testcr.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, projection, whereClause,
                            null, null);
            int _id = 0;
            String videoPath = "";
            if (cursor == null || cursor.getCount() == 0) {
                    return null;
            }
            if (cursor.moveToFirst()) {

                    int _idColumn = cursor.getColumnIndex(MediaStore.Video.Media._ID);
                    int _dataColumn = cursor.getColumnIndex(MediaStore.Video.Media.DATA);
                    do {
                            _id = cursor.getInt(_idColumn);
                            videoPath = cursor.getString(_dataColumn);
                    } while (cursor.moveToNext());
            }
            cursor.close();
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inDither = false;
            options.inPreferredConfig = Bitmap.Config.RGB_565;
            Bitmap bitmap = MediaStore.Video.Thumbnails.getThumbnail(cr, _id, Images.Thumbnails.MINI_KIND,
                            options);
            return bitmap;
    }(2)人為創建縮略圖要耗費一點時間


[java]
復制代碼 代碼如下:

/**
    * 獲取視頻縮略圖
    * @param videoPath
    * @param width
    * @param height
    * @param kind
    * @return
    */
   private Bitmap getVideoThumbnail(String videoPath, int width , int height, int kind){
    Bitmap bitmap = null;
    bitmap = ThumbnailUtils.createVideoThumbnail(videoPath, kind);
    bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height, ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
    return bitmap;
   }

 /**
     * 獲取視頻縮略圖
     * @param videoPath
     * @param width
     * @param height
     * @param kind
     * @return
     */
    private Bitmap getVideoThumbnail(String videoPath, int width , int height, int kind){
  Bitmap bitmap = null;
  bitmap = ThumbnailUtils.createVideoThumbnail(videoPath, kind);
  bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height, ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
  return bitmap;
    }


2、圖片縮略圖

[java]

復制代碼 代碼如下:

/**
    * 
    * @param context
    * @param cr
    * @param Imagepath
    * @return
    */
   public static Bitmap getImageThumbnail(Context context, ContentResolver cr, String Imagepath) { 
           ContentResolver testcr = context.getContentResolver(); 
           String[] projection = { MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID, }; 
           String whereClause = MediaStore.Images.Media.DATA + " = '" + Imagepath + "'"; 
           Cursor cursor = testcr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, whereClause, 
                           null, null); 
           int _id = 0; 
           String imagePath = ""; 
           if (cursor == null || cursor.getCount() == 0) { 
                   return null; 
           } 
           if (cursor.moveToFirst()) { 

                   int _idColumn = cursor.getColumnIndex(MediaStore.Images.Media._ID); 
                   int _dataColumn = cursor.getColumnIndex(MediaStore.Images.Media.DATA); 

                   do { 
                           _id = cursor.getInt(_idColumn); 
                           imagePath = cursor.getString(_dataColumn); 
                   } while (cursor.moveToNext()); 
           } 
           cursor.close();
           BitmapFactory.Options options = new BitmapFactory.Options(); 
           options.inDither = false; 
           options.inPreferredConfig = Bitmap.Config.RGB_565; 
           Bitmap bitmap = MediaStore.Images.Thumbnails.getThumbnail(cr, _id, Images.Thumbnails.MINI_KIND, 
                           options); 
           return bitmap; 
   }

 /**
     *
     * @param context
     * @param cr
     * @param Imagepath
     * @return
     */
    public static Bitmap getImageThumbnail(Context context, ContentResolver cr, String Imagepath) {
            ContentResolver testcr = context.getContentResolver();
            String[] projection = { MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID, };
            String whereClause = MediaStore.Images.Media.DATA + " = '" + Imagepath + "'";
            Cursor cursor = testcr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, whereClause,
                            null, null);
            int _id = 0;
            String imagePath = "";
            if (cursor == null || cursor.getCount() == 0) {
                    return null;
            }
            if (cursor.moveToFirst()) {

                    int _idColumn = cursor.getColumnIndex(MediaStore.Images.Media._ID);
                    int _dataColumn = cursor.getColumnIndex(MediaStore.Images.Media.DATA);

                    do {
                            _id = cursor.getInt(_idColumn);
                            imagePath = cursor.getString(_dataColumn);
                    } while (cursor.moveToNext());
            }
            cursor.close();
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inDither = false;
            options.inPreferredConfig = Bitmap.Config.RGB_565;
            Bitmap bitmap = MediaStore.Images.Thumbnails.getThumbnail(cr, _id, Images.Thumbnails.MINI_KIND,
                            options);
            return bitmap;
    }

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 久久艹一区 | 五月天堂婷婷 | 国产无限资源在线观看 | 一二区成人影院电影网 | 中文字幕免费看 | 嫩嫩的freehdxxx | 91看片在线观看视频 | 久久亚洲国产午夜精品理论片 | 精品国产高清一区二区三区 | 涩涩伊人 | 一级黄色大片在线观看 | 一级黄片毛片免费看 | 日韩黄色av网站 | 成人在线视频网 | 久久久久久高清 | 免费看黄色一级片 | 狠狠操操 | 欧美精品一区二区三区久久久 | 91成人久久| 嫩嫩的freehdxxx | 久久综合综合久久 | 日本黄色免费播放 | 国产1区2区3区在线观看 | 日韩精品a在线观看 | 欧美日韩一区三区 | 成人午夜久久 | 中文字幕在线看第二 | 精品黑人一区二区三区国语馆 | 久久久久久久久成人 | 精品国产观看 | 3xxx| 成人免费av在线播放 | 97久色| 性日本xxx| 国产超碰人人做人人爱ⅴa 国产精品久久久久久久hd | 久久精品资源 | xxxx18韩国护士hd老师 | 久久久久久中文字幕 | 欧美77 | 国产91丝袜在线播放0 | 四虎久草 |