Universal Image Loader加载速度较慢

时间:2013-07-26 02:51:54

标签: android universal-image-loader

我正在使用UIL库编写自定义库,为了测试性能,我修改了ImagePagerActivity(示例代码)以从sdcard加载图像。一切正常,但加载速度太慢,有时甚至需要5秒才能加载单个图像。但是,如果我使用内置库,它的速度更快,并在几毫秒内加载更多图像。以下是修改后的onCreate

的片段
    File file = new File(Environment.getExternalStorageDirectory(), "dcim/100MEDIA/");
    File[] images = file.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String filename) {
            return filename.toLowerCase(Locale.US).endsWith(".jpg");
        }
    });
    String[] imageUrls = new String[images.length];
    for (int a = 0; a < imageUrls.length; a++)
        imageUrls[a] = "file://" + images[a].getAbsolutePath();

    options = new DisplayImageOptions.Builder().showImageForEmptyUri(R.drawable.ic_empty)
            .showImageOnFail(R.drawable.ic_error).resetViewBeforeLoading(true).cacheOnDisc(true)
            .cacheInMemory(true).imageScaleType(ImageScaleType.EXACTLY).bitmapConfig(Bitmap.Config.RGB_565)
            .displayer(new FadeInBitmapDisplayer(300)).build();
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this)
            .defaultDisplayImageOptions(options).discCacheExtraOptions(800, 800, CompressFormat.PNG, 0, null)
            .build();
    ImageLoader.getInstance().init(config);

并且很少修改ImagePagerAdapter

            @Override
            public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                spinner.setVisibility(View.GONE);
                 Toast.makeText(ImagePagerActivity.this, loadedImage.getWidth() + " x " + loadedImage.getHeight(),
                 Toast.LENGTH_SHORT).show();
            }

通常常见的图片尺寸为2592x1552

UIL 1.8.6

Android版:4.0.3

其他与示例代码

相同

1 个答案:

答案 0 :(得分:0)

您的ImageLoaderConfiguration是什么样的?你设置了什么threadPriority?此外,ImageScaleType.EXACTLY创建另一个位图,因此这将增加加载时间。对于我的ImageLoaderConfiguration,我将threadPriority设置为Thread.MAX_PRIORITY,并将threadPoolSize设置为5:

    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
            getApplicationContext()).threadPriority(Thread.MAX_PRIORITY)
            .memoryCacheSize(memoryCacheSize)
            .memoryCache(new WeakMemoryCache())
            .denyCacheImageMultipleSizesInMemory().threadPoolSize(5)
            .discCacheFileNameGenerator(new MyFileNameGenerator())
            .tasksProcessingOrder(QueueProcessingType.LIFO)// .enableLogging()
            .build();