概述
获取图片缩略图:
- byte[] imageByte=getImageFromURL(urlPath.trim());
- //以下是把图片转化为缩略图再加载
- BitmapFactory.Options options = new BitmapFactory.Options();
- options.inJustDecodeBounds = true;
- BitmapFactory.decodeByteArray(imageByte, 0, imageByte.length,<span style="background-color: rgb(255, 255, 255);">options </span>); <span style="line-height: 25px; font-size: 14px; white-space: normal;"> //此时返回bitmap为空 </span>
byte[] imageByte=getImageFromURL(urlPath.trim());
//以下是把图片转化为缩略图再加载
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(imageByte, 0, imageByte.length,options );
//此时返回bitmap为空
- 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); //返回缩略图
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);
//返回缩略图
获取视频缩略图:
/**
* 根据视频Uri地址取得指定的视频缩略图
* @param cr
* @param uri 本地视频Uri标示
* @return 返回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;
- }
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类型数据
*/
- 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;
- }
最后
以上就是忐忑招牌为你收集整理的android获取图片和视频的缩略图的全部内容,希望文章能够帮你解决android获取图片和视频的缩略图所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复