使用位图的缩略图问题 [英] Problems using bitmaps for thumbnails

查看:166
本文介绍了使用位图的缩略图问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让一个应用程序,需要的视频,然后显示在GridView的影片。我已经得到了到所有的视频​​缩略图像他们应该显示在GridView的地步。不过,我的问题是,我使用的方法有很多的滞后时间。这需要一些时间来GridView控件加载,当我尝试滚动总有一些滞​​后。这是最有可能是由于我使用位图每一个视频缩略图的事实。

I'm trying to make an app that takes videos and then displays the videos in a gridview. I have gotten to the point where all the video thumbnails are showing up in the gridview like they should. However, my problem is that the method I am using has a lot of lag time. It takes some time to get the gridview loaded and when I try to scroll there is always some sort of lag. This is most likely due to the fact that I'm using bit maps for every video thumbnail.

我不知道我能做些什么,使这个有很多更快,更流畅。我的code如下公布。

I was wondering what I could do to make this a lot quicker and smoother. My code is posted below.

class VideoAdapter extends BaseAdapter {
Context context; 
ArrayList<String> videopathlist;
Bitmap bmthumb;


VideoAdapter(Context c, ArrayList<String> filepathlist){
    context = c;
    videopathlist = new ArrayList<String>();
    this.videopathlist.addAll(filepathlist);
    Log.i(TAG, "" + videopathlist);
}

@Override 
public int getCount() {
    return videopathlist.size();
}

@Override
public Object getItem(int position) {
    return videopathlist.get(position);
}

@Override
public long getItemId(int arg0) {
    return 0;
}

@Override
public View getView(int posiiton, View arg1, ViewGroup arg2) {
    ImageView imageview = new ImageView(context);
     bmthumb = ThumbnailUtils.createVideoThumbnail(videopathlist.get(posiiton), MediaStore.Video.Thumbnails.MINI_KIND);
     if (bmthumb != null) {
         Log.i(TAG1, "There is a thumbnail");
         imageview.setImageBitmap(bmthumb);
     } else {
         Log.i(TAG1, "There is NOT a thumbnail");
     }
     imageview.setScaleType(ImageView.ScaleType.CENTER_CROP);
     imageview.setLayoutParams(new GridView.LayoutParams(160, 160));


    return imageview;
}

感谢您的帮助。

推荐答案

2的事情:

使用一个ViewHolder缓存的一切,如下所述:制作的ListView滚动平滑(适用于GridView的太)

Use a ViewHolder to cache everything, as described here: Making ListView Scrolling Smooth (applies to GridViews too)

此外,使用ImageLoader的动态加载图像。有许多可用的,或者你可以建立自己的。这里有一些:

Also, use an ImageLoader to load images dynamically. There are many available or you can build your own. Here are some:

  • Volley
  • Android-Universal-Image-Loader
  • ImageLoader

所有这些装载机使用位图缓存这里描述:位图缓存

All these loaders make use of Bitmap caches as described here: Caching Bitmaps

此外,你可能会真的返回了视图时创建缩略图位图。这令我非常昂贵的。我会做这个作为一个单独的步骤,无关显示它们。例如,打完折的的AsyncTask 时,首次创建活动产生任何新的缩略图。然后在你的适配器只查询 MediaStore 来获取生成的缩略图。

Also, you could potentially be actually creating the thumbnail bitmaps when returning the view. This strikes me as very expensive. I would do this as a seperate step, unrelated to displaying them. For example, kick off an AsyncTask when your activity is first created to generate any new thumbnails. Then in your adapter just query the MediaStore to get the generated thumbnails.

这篇关于使用位图的缩略图问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆