是否可以使用Universal image Loader for android?加载缩略图。我在Sdcard中获得了图像和视频文件的缩略图然后我不知道如何在gridview中使用这个库来显示这些缩略图所以请告诉我任何人都知道该怎么做?
我从这段代码中得到了缩略图:
protected Integer doInBackground(Integer... params) {
// TODO Auto-generated method stub
final String[] columns = { MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID }; // Images getting
final String orderBy = MediaStore.Images.Media.DATE_TAKEN;
imagecursor = mContext.getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null,
null, orderBy);
int image_column_index = imagecursor.getColumnIndex(MediaStore.Images.Media._ID);
this.count = imagecursor.getCount();
/*this.count = params[0];
if(count == 0)
this.count = imagecursor.getCount();
else if(count >= 12)
*/
bitList = new ArrayList<Bitmap>();
arrPathList = new ArrayList<String>();
selectedPath = new ArrayList<String>();
for (int i = 0; i < this.count; i++) {
imagecursor.moveToPosition(i);
int id = imagecursor.getInt(image_column_index);
int dataColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Media.DATA);
bitList.add( MediaStore.Images.Thumbnails.getThumbnail(
mContext.getContentResolver(), id,
MediaStore.Images.Thumbnails.MICRO_KIND, null));
arrPathList.add(imagecursor.getString(dataColumnIndex));
}
this.durationcount = new ArrayList<String>(); // Video Getting
final String[] parameters = { MediaStore.Video.Media.DATA, MediaStore.Video.Media._ID, MediaStore.Video.Media.DURATION , MediaStore.Video.Media.MIME_TYPE}; // Videos getting
final String orderBy_v = MediaStore.Video.Media._ID;
videocursor = mContext.getContentResolver().query(
MediaStore.Video.Media.EXTERNAL_CONTENT_URI, parameters, null,
null, orderBy_v);
int video_column_index = videocursor.getColumnIndex(MediaStore.Video.Media._ID);
int video_column_duration = videocursor.getColumnIndexOrThrow(MediaStore.Video.VideoColumns.DURATION); // for duration of the video
totalCount = imagecursor.getCount() + videocursor.getCount(); /// Checking
durationcount_a = new String[imagecursor.getCount() + videocursor.getCount()];
for(int i = 0; i < videocursor.getCount(); i ++){
videocursor.moveToPosition(ii);
int id_v = videocursor.getInt(video_column_index);
int datacolumn_v = videocursor.getColumnIndex(MediaStore.Video.Media.DATA);
long duration = videocursor.getInt(video_column_duration); // getting duration of the every videos
String hms = String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(duration),
TimeUnit.MILLISECONDS.toMinutes(duration) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(duration)),
TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration)));
durationcount.add(hms);
durationcount_a[(imagecursor.getCount()) + ii] = hms;
bitList.add(MediaStore.Video.Thumbnails.getThumbnail(mContext.getContentResolver(), id_v,
MediaStore.Video.Thumbnails.MICRO_KIND, null));
arrPathList.add(videocursor.getString(datacolumn_v));
}
thumbnailsselection = new boolean[totalCount];
return null;
}
提前致谢。
答案 0 :(得分:1)
你必须使用通用图像加载器来获取缩略图的路径或uri。
看到这个以获得uri: -
Get thumbnail Uri/path of the image stored in sd card + android
我也曾在同一类项目上工作并通过git-hub托管它..我有两个版本,一个没有ImageLoader,另一个没有Imageloader ..现在我只托管了前一个: -
这是路径https://github.com/r4jiv007/CustomFilePicker.git
这是我使用的方法: -
private String getImageThumbnail(int id) {
final String thumb_DATA = MediaStore.Images.Thumbnails.DATA;
final String thumb_IMAGE_ID = MediaStore.Images.Thumbnails.IMAGE_ID;
Uri uri = thumbUri;
String[] projection = {thumb_DATA, thumb_IMAGE_ID};
String selection = thumb_IMAGE_ID + "=" + id + " AND " + MediaStore.Images.Thumbnails.KIND + "=" + MediaStore.Images.Thumbnails.MINI_KIND;
Cursor thumbCursor = getContentResolver().query(uri, projection, selection, null, null);
String thumbPath = null;
Bitmap thumbBitmap = null;
if (thumbCursor != null && thumbCursor.getCount() > 0) {
thumbCursor.moveToFirst();
int thCulumnIndex = thumbCursor.getColumnIndex(thumb_DATA);
thumbPath = thumbCursor.getString(thCulumnIndex);
/*
Toast.makeText(getApplicationContext(),
thumbPath,
Toast.LENGTH_LONG).show();*/
// thumbBitmap = BitmapFactory.decodeFile(thumbPath);
}
Log.i("ImageMiniKind", thumbPath + "");
return thumbPath;
}
你必须使用: -
imageLoader.displayImage("file://" + fileX.getmThumbPath() + "", imageView, options);
用于加载图像..还要注意有时候图像没有缩略图!!
用于加载视频文件的缩略图
private String getVideoThumbnail(int id) {
final String thumb_DATA = MediaStore.Video.Thumbnails.DATA;
final String thumb_VIDEO_ID = MediaStore.Video.Thumbnails.VIDEO_ID;
Uri uri = MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI;
String[] projection = {thumb_DATA, thumb_VIDEO_ID};
String selection = thumb_VIDEO_ID + "=" + id + " AND " + MediaStore.Video.Thumbnails.KIND + "=" + MediaStore.Video.Thumbnails.MINI_KIND;
Cursor thumbCursor = getContentResolver().query(uri, projection, selection, null, null);
String thumbPath = null;
// Bitmap thumbBitmap = null;
if (thumbCursor.moveToFirst()) {
int thCulumnIndex = thumbCursor.getColumnIndex(thumb_DATA);
thumbPath = thumbCursor.getString(thCulumnIndex);
}
return thumbPath;
}
现在你所要做的就是将路径传递给imageloader库