22

您好,我正在从相机捕获图像并将其保存到 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);

有人可以帮我做什么吗?

4

2 回答 2

41

如果您从 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);
于 2013-09-20T09:16:10.227 回答
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)
            }
        }
于 2020-01-03T17:51:39.997 回答