最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

android 獲取視頻,圖片縮略圖的具體實(shí)現(xiàn)

 更新時(shí)間:2013年06月13日 11:23:30   作者:  
android 獲取視頻,圖片縮略圖的具體實(shí)現(xiàn),需要的朋友可以參考一下

1、獲取視頻縮略圖有兩個(gè)方法(1)通過內(nèi)容提供器來(lái)獲取(2)人為創(chuàng)建縮略圖

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

[java]

復(fù)制代碼 代碼如下:

/**
     * @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)人為創(chuàng)建縮略圖要耗費(fèi)一點(diǎn)時(shí)間


[java]
復(fù)制代碼 代碼如下:

/**
    * 獲取視頻縮略圖
    * @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]

復(fù)制代碼 代碼如下:

/**
    * 
    * @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;
    }

相關(guān)文章

  • Android仿eleme點(diǎn)餐頁(yè)面二級(jí)聯(lián)動(dòng)列表

    Android仿eleme點(diǎn)餐頁(yè)面二級(jí)聯(lián)動(dòng)列表

    本站一直在點(diǎn)外賣,于是心血來(lái)潮就像仿餓了么做個(gè)站,接下來(lái)通過本文給大家介紹android 二級(jí)聯(lián)動(dòng)列表,仿eleme點(diǎn)餐頁(yè)面的相關(guān)資料,需要的朋友可以參考下
    2016-10-10
  • Android 使用registerReceiver注冊(cè)BroadcastReceiver案例詳解

    Android 使用registerReceiver注冊(cè)BroadcastReceiver案例詳解

    這篇文章主要介紹了Android 使用registerReceiver注冊(cè)BroadcastReceiver案例詳解,本篇文章通過簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-08-08
  • Android 設(shè)置Edittext獲取焦點(diǎn)并彈出軟鍵盤

    Android 設(shè)置Edittext獲取焦點(diǎn)并彈出軟鍵盤

    本文主要介紹了Android設(shè)置Edittext獲取焦點(diǎn)并彈出軟鍵盤的實(shí)現(xiàn)代碼。具有很好的參考價(jià)值。下面跟著小編一起來(lái)看下吧
    2017-04-04
  • Android實(shí)現(xiàn)Service重啟的方法

    Android實(shí)現(xiàn)Service重啟的方法

    這篇文章主要介紹了Android實(shí)現(xiàn)Service重啟的方法,涉及Android操作Service組件實(shí)現(xiàn)服務(wù)重啟的功能,需要的朋友可以參考下
    2015-05-05
  • Android RecyclerView網(wǎng)格布局示例解析

    Android RecyclerView網(wǎng)格布局示例解析

    這篇文章主要介紹了Android RecyclerView網(wǎng)格布局示例解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-12-12
  • 實(shí)現(xiàn)activity管理器一次退出所有activity

    實(shí)現(xiàn)activity管理器一次退出所有activity

    退出所有Activity網(wǎng)上有很多很多種說(shuō)法,推薦的一種方法是自定義一個(gè)Activity管理器,來(lái)管理所有已打開的Activity,要退出的時(shí)候再通過這個(gè)管理器來(lái)退出所有Activity,下面是一個(gè)簡(jiǎn)單的Activity管理器代碼
    2014-01-01
  • android bitmap compress(圖片壓縮)代碼

    android bitmap compress(圖片壓縮)代碼

    android bitmap compress(圖片壓縮)代碼,需要的朋友可以參考一下
    2013-06-06
  • Android中Intent與Bundle的使用詳解

    Android中Intent與Bundle的使用詳解

    這篇文章主要給大家總結(jié)介紹了關(guān)于Android中傳值Intent與Bundle的關(guān)系,文中通過示例代碼以及圖文介紹的非常詳細(xì),對(duì)各位Android開發(fā)者們具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧<BR>
    2022-11-11
  • Android編程實(shí)現(xiàn)WebView全屏播放的方法(附源碼)

    Android編程實(shí)現(xiàn)WebView全屏播放的方法(附源碼)

    這篇文章主要介紹了Android編程實(shí)現(xiàn)WebView全屏播放的方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了Android實(shí)現(xiàn)WebView全屏播放的布局與功能相關(guān)技巧,需要的朋友可以參考下
    2015-11-11
  • Android 跨進(jìn)程模擬按鍵(KeyEvent )實(shí)例詳解

    Android 跨進(jìn)程模擬按鍵(KeyEvent )實(shí)例詳解

    這篇文章主要介紹了Android 跨進(jìn)程模擬按鍵(KeyEvent )實(shí)例詳解的相關(guān)資料,類似手機(jī)遙控器的需求就可以這么做,需要的朋友可以參考下
    2016-11-11

最新評(píng)論

乌兰浩特市| 波密县| 呈贡县| 乐清市| 贞丰县| 鹤庆县| 察哈| 攀枝花市| 同仁县| 甘德县| 吉木萨尔县| 巴楚县| 中卫市| 陆良县| 曲靖市| 驻马店市| 木里| 德保县| 高安市| 屯留县| 革吉县| 永川市| 德清县| 榆林市| 社旗县| 延庆县| 安乡县| 夏津县| 延边| 延安市| 鹤壁市| 手游| 邵阳市| 河北省| 宁都县| 宜兰市| 周口市| 吴旗县| 汾西县| 社旗县| 威信县|