97干视频,99国产精品懂色,亚洲精品99久久久久中文字幕,伊人五月丁香综合AⅤ,国产精品成人免费999

  您的位置:華清遠(yuǎn)見教育科技集團(tuán) >> 新聞動態(tài) >> Android資料 >> Android中多媒體縮略圖的生成  
 
Android中多媒體縮略圖的生成
分享到:

縮略圖是智能終端中常用的一個(gè)功能,在Android,多媒體文件(視頻和圖片)都是有縮略圖的,在很多應(yīng)用中,我們需要獲取這些縮略圖,下面是Android的一個(gè)實(shí)現(xiàn):

代碼:縮略圖的實(shí)現(xiàn)

private Bitmap createThumbnailBitmap(int thumbnailBoundsLimit, Uri uri)
    {
    int outWidth=mWidth;
    int outHeight=mHeight;
    int s=1;
    while ((outWidth / s > thumbnailBoundsLimit)|| (outHeight / s > thumbnailBoundsLimit))
        {
            s *=2;
        }
    if (Log.isLoggable(LogTag.APP, Log.VERBOSE))
        {
            Log.v(TAG, "createThumbnailBitmap: scale="+s+", w="+outWidth/s+",h="+outHeight/s);
        }
    BitmapFactory.Options options=new BitmapFactory.Options();
    options.inSampleSize=s;
    InputStream input=null;
    try {
    input=mContext.getContentResolver().openInputStream(uri);    //打開輸入流
    return BitmapFactory.decodeStream(input, null, options);     //圖像解碼
        }
    catch (FileNotFoundException e)
        {
    Log.e(TAG, e.getMessage(), e);
    return null;
        }
    catch (OutOfMemoryError ex)
        {
            MessageUtils.writeHprofDataToFile();
            throw ex;
        }
    finally {
        if (input !=null)
            {
            try {
                input.close();
                }
            catch (IOException e)
                {
                Log.e(TAG, e.getMessage(), e);
                }
            }
        }
    }

在Android中,對于SD卡中的文件可以通過數(shù)據(jù)庫android.provider.MediaStore.Images. Thumbnails來讀取。

具體的縮略圖可以通過getThumbnail()獲取。在Android中,縮略圖分為微型(MICRO_KIND)和迷你型(MINI_KIND)兩種縮略模式;贛ediaStore的數(shù)據(jù)庫的好處是提取縮略圖時(shí),不用自己計(jì)算。

 更多相關(guān)文章

·Android 圖像縮放之bitmap類
·Android 2D圖像處理基本接口
·Android HTML5視頻播放
·Android基于MediaPlayer的視頻播放
·Android 中如何使用SIP服務(wù)
·Android音頻混響特效的設(shè)置