默认情况下UIL不支持方案(协议)您应该自己实现此支持

时间:2013-09-20 09:12:29

标签: android universal-image-loader

您好我正在从相机捕获图像并将其保存到SDCARD并通过Universal Image Loader加载但每次出现错误时都会出现

       09-20 14:38:22.617: E/ImageLoader(16626): 
      UIL doesn't support scheme(protocol) by default [/mnt/sdcard/temp_photobooth.png]. You should implement this support yourself (BaseImageDownloader.getStreamFromOtherSource(...))



     imgLoader.displayImage(Environment
                        .getExternalStorageDirectory().toString()
                        + File.separator + Const.TEMP_FILE, choosen_image);

任何人都可以帮助我,我该怎么做呢?

2 个答案:

答案 0 :(得分:39)

如果要从SDCARD加载图像,则应在路径前加file:///

String imageUri = "http://example.com/image.png"; // from Web
String imageUri = "file:///mnt/sdcard/image.png"; // from SD card
String imageUri = "content://media/external/audio/albumart/13"; // from content provider
String imageUri = "assets://image.png"; // from assets
String imageUri = "drawable://" + R.drawable.image; // from drawables (only images, non-9patch)

所以你必须这样写:

imgLoader.displayImage("file:///"+Environment
    .getExternalStorageDirectory().toString() + File.separator + Const.TEMP_FILE, choosen_image);

答案 1 :(得分:0)

lateinit var imageLoader:ImageLoader

在onCreate

val config =
        ImageLoaderConfiguration.Builder(mContext)
            .threadPoolSize(5)
            .threadPriority(Thread.MIN_PRIORITY + 2)
            .defaultDisplayImageOptions(DisplayImageOptions.createSimple())
            .build()

    imageLoader = ImageLoader.getInstance()
    imageLoader.init(config);

并用于:例如在回收站视图中绑定:

var options : DisplayImageOptions?
val strFileName :String = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString()+"/FolderName/"+"filename.jpg"
        val imgFile = File(strFileName)

        if(strFileName!="null" && imgFile.exists()) {
            options = DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.ic_logo_white)
                .showImageForEmptyUri(R.drawable.ic_logo_white)
                .showImageOnFail(R.drawable.ic_logo_white)
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .considerExifParams(true)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .build()
            if (strFileName.contains("http")) {
                imageLoader.displayImage(
                    strFileName,
                    view.imageView,
                    options
                )
            } else {
                imageLoader.displayImage("file:///"+strFileName, view.imageView)
            }
        }