获取图片缩略图:
获取视频缩略图:
/**
* 根据视频在手机中的地址路径取得指定的视频缩略图
* @param cr
* @param fileName 本地视频地址
* @return 返回bitmap类型数据
*/
01
02
03
04
05
|
byte
[] imageByte=getImageFromURL(urlPath.trim());
//以下是把图片转化为缩略图再加载
BitmapFactory.Options options =
new
BitmapFactory.Options();
options.inJustDecodeBounds =
true
;
BitmapFactory.decodeByteArray(imageByte,
0
, imageByte.length,<SPAN style=
"BACKGROUND-COLOR: #ffffff"
>options </SPAN>); <SPAN style=
"LINE-HEIGHT: 25px; WHITE-SPACE: normal; FONT-SIZE: 14px"
>
//此时返回bitmap为空 </SPAN>
|
01
02
03
04
05
06
07
|
options.inJustDecodeBounds =
false
;
int
be = (
int
)(options.outHeight / (
float
)
200
);
if
(be <=
0
){
be =
1
;
}
options.inSampleSize = be;
return
BitmapFactory.decodeByteArray(imageByte,
0
, imageByte.length,options);
//返回缩略图
|
获取视频缩略图:
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
/**
* 根据视频Uri地址取得指定的视频缩略图
* @param cr
* @param uri 本地视频Uri标示
* <a href="\"http://www.eoeandroid.com/home.php?mod=space&uid=7300\"" target="\"_blank\"">@return</a> 返回bitmap类型数据
*/
public
static
Bitmap getVideoThumbnail(ContentResolver cr, Uri uri) {
Bitmap bitmap =
null
;
BitmapFactory.Options options =
new
BitmapFactory.Options();
options.inDither =
false
;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Cursor cursor = cr.query(uri,
new
String[] { MediaStore.Video.Media._ID },
null
,
null
,
null
);
if
(cursor ==
null
|| cursor.getCount() ==
0
) {
return
null
;
}
cursor.moveToFirst();
String videoId = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media._ID));
//image id in image table.s
if
(videoId ==
null
) {
return
null
;
}
cursor.close();
long
videoIdLong = Long.parseLong(videoId);
bitmap = MediaStore.Video.Thumbnails.getThumbnail(cr, videoIdLong,Images.Thumbnails.MICRO_KIND, options);
return
bitmap;
}
|
/**
* 根据视频在手机中的地址路径取得指定的视频缩略图
* @param cr
* @param fileName 本地视频地址
* @return 返回bitmap类型数据
*/
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
public
static
Bitmap getVideoThumbnail(ContentResolver cr, Uri uri) {
Bitmap bitmap =
null
;
BitmapFactory.Options options =
new
BitmapFactory.Options();
options.inDither =
false
;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Cursor cursor = cr.query(uri,
new
String[] { MediaStore.Video.Media._ID },
null
,
null
,
null
);
if
(cursor ==
null
|| cursor.getCount() ==
0
) {
return
null
;
}
cursor.moveToFirst();
String videoId = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media._ID));
//image id in image table.s
if
(videoId ==
null
) {
return
null
;
}
cursor.close();
long
videoIdLong = Long.parseLong(videoId);
bitmap = MediaStore.Video.Thumbnails.getThumbnail(cr, videoIdLong,Images.Thumbnails.MICRO_KIND, options);
return
bitmap;
}
转自:http://www.eoeandroid.com/thread-234926-1-1.html
|